Java 第四次作业
原程序耗时
修改程序如下:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class Copy {
long time=System.currentTimeMillis();
public void copy(){
try {
FileInputStream fis =new FileInputStream("a.mp3");
FileOutputStream fos =new FileOutputStream("w.mp3");
byte[] buf = new byte[1024*1000];
int len = 0 ;
while((len=fis.read(buf)) != -1){
fos.write(buf,0,len);
}
fis.close();
fos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("执行耗时 : "+(System.currentTimeMillis()-time)/1000f+" 秒 ");
}
public static void main(String []args){
Copy a= new Copy();
a.copy();
}
}
复制文件成功:
复制文件耗时: