改进代码,提高运行速率,我感觉这次作业难度还是大,不过经过别人讲解也明白了实质和每一条代码作用,继续加油吧
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");
}
}