第四周作业
很明显提高了复制的时间
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class CopyFile{
long a=System.currentTimeMillis();
public void fz(){
try
{
FileInputStream fis =new FileInputStream("a.mp3");
FileOutputStream fos =new FileOutputStream("f.mp3");
int read=fis.read();
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) {
e.printStackTrace();
}System.out.println("耗时 : "+(System.currentTimeMillis()-a)/1000f+" 秒 ");
}
public static void main(String []args){
CopyFile cf= new CopyFile();
cf.fz():
}
}