改进代码,提高运行速率,我感觉这次作业难度还是大,不过经过别人讲解也明白了实质和每一条代码作用,继续加油吧
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyFile {
public static void main (String[]args){
long startTime=System.currentTimeMillis();
try{
FileInputStream fis=new FileInputStream("a.jpg");
FileOutputStream fos=new FileOutputStream("temp.jpg");
int read=fis.read();
while(read!=-1){
fos.write(read);
read=fis.read();
}
fis.close();
fos.close();
}
catch(IOException e){
e.printStackTrace();
}
long endTime=System.currentTimeMillis();
System.out.println("程序运行时间:"+(endTime-startTime)+"ms");

		}

}

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyFile {
public static void main (String[]args){
long startTime=System.currentTimeMillis();
try{
FileInputStream fis=new FileInputStream("a.jpg");
FileOutputStream fos=new FileOutputStream("temp.jpg");
byte[]buffer=new byte[1024];
int read=fis.read(buffer);
while(read!=-1){
fos.write(read);
read=fis.read();
}
fis.close();
fos.close();
}
catch(IOException e){
e.printStackTrace();
}
long endTime=System.currentTimeMillis();
System.out.println("程序运行时间:"+(endTime-startTime)+"ms");

		}

}

posted on 2016-04-08 21:59  14软件G1班陈宏娟  阅读(122)  评论(0编辑  收藏  举报