程序实现的功能:
以字节流的方式,将source文件夹中的aiwo.mp3文件复制到target文件夹的aiwo.mp3,且统计输出复制完成所需的时间。
public class Test6 {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
long startTime=System.currentTimeMillis();
FileInputStream fis = new
FileInputStream("C:\\Users\\86137\\Desktop\\lpt\\source\\aiwo.mp3");
BufferedInputStream bis = new BufferedInputStream(fis);
FileOutputStream fos = new
FileOutputStream("C:\\Users\\86137\\Desktop\\lpt\\target\\aiwo.mp3");
BufferedOutputStream bos = new BufferedOutputStream(fos);
byte[] buffer = new byte[1024];
int len = 0;
while((len = bis.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.flush();
fis.close();
fos.close();
long endTime=System.currentTimeMillis();
System.out.println("程序运行时间:"+(endTime-startTime)+"ms");
}
}