📄 copyfile.java
字号:
package java_io;
import java.io.*;
/**
*
* <p>Title: FileInputStream和FileOutputStream共同使用</p>
* 将一个二进制文件的内容复制到另一个二进制文件中。
*
*/
public class CopyFile {
public static void main(String args[]) {
int i;
FileInputStream fin = null;
FileOutputStream fout = null;
try {
//打开输入流
try {
fin = new FileInputStream("testFile/testPhoto.jpg");
} catch (FileNotFoundException e) {
System.out.println("Input file not Found.");
}
//打开输出流
try {
fout = new FileOutputStream("CopytestPhoto.jpg");
} catch (FileNotFoundException ex) {
System.out.println("Error Opening Output File.");
}
//进行文件拷贝。
while ((i = fin.read()) != -1) {
fout.write(i);
}
fin.close();
fout.close();
System.out.println("File Operate Success!");
} catch (IOException ex1) {
System.out.println("File Error!");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -