FileInputStream和FileOutputStream拷贝文件
package FileWork;
import java.io.*;
public class FileCopy {
public static void main(String[] args)throws IOException {
FileInputStream fis=null;
FileOutputStream fos=null;
try {
fis=new FileInputStream("D:\\image\\1.jpg");
fos=new FileOutputStream("D:\\image\\2.jpg");
long begintime=System.currentTimeMillis();
byte[] bys=new byte[50];
int len=0;
while((len = fis.read(bys))!=-1) {
fos.write(bys,0,len);
}
long endtime=System.currentTimeMillis();
System.out.println((endtime-begintime)+"ms");
}catch(Exception e){
e.printStackTrace();
}finally {
if(fis!=null) {
try {
fis.close();
}catch(IOException e) {
e.printStackTrace();
}
}
if(fos!=null) {
try {
fos.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
}
}