JAVA(IO流)文件复制

时间:2022-06-16 18:26:51
 package com.am;

 import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; public class TuPian { public static void main(String[] args) {
FileInputStream f1 = null;
FileOutputStream f2 = null;
try {
f1 = new FileInputStream("E:\\5s.JPG");
f2 = new FileOutputStream("E:\\6s.jpg");
byte[] bytes = new byte[1024];
int len = 0;
while ((len=f1.read(bytes))!=-1) {
f2.write(bytes,0,len);
}
} catch (IOException e) {
e.printStackTrace();
}
if (f1!=null) {
try {
f1.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (f2!=null) {
try {
f2.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}