📄 fileoutputstreamdemo.java
字号:
import java.io.*;
// Chapter 4, Listing 2
public class FileOutputStreamDemo
{
public static void main(String args[])
{
// Two parameters are required, the source and destination
if (args.length != 2)
{
System.err.println ("Syntax - FileOutputStreamDemo src dest");
return;
}
String source = args[0];
String destination = args[1];
try
{
// Open source file for input
InputStream input = new FileInputStream( source );
System.out.println ("Opened " + source + " for reading.");
// Ouput output file for output
OutputStream output = new FileOutputStream ( destination );
System.out.println ("Opened " + destination + " for writing.");
int data = input.read();
while ( data != -1)
{
// Write byte of data to our file
output.write (data);
// Read next byte
data=input.read();
}
// Close both streams
input.close();
output.close();
System.out.println ("I/O streams closed");
}
catch (IOException ioe)
{
System.err.println ("I/O error - " + ioe);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -