字节流练习:图片复制
package com.itheima.demo03.CopyFile;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
public class Demo01CopyFile {
public static void main(String[] args) throws IOException {
long s = System.currentTimeMillis();
FileInputStream fis = new FileInputStream("C:\\Users\\联想\\Pictures\\Camera Roll\\源.jpg");
FileOutputStream fos = new FileOutputStream("C:\\Users\\联想\\Documents\\copy.jpg");
byte[] bytes = new byte[1024];
int len = 0;
while ((len = fis.read(bytes)) != -1) {
fos.write(bytes, 0, len);
}
fos.close();
fis.close();
long e = System.currentTimeMillis();
System.out.println("复制文件共耗时:" + (e - s) + "毫秒");
}
}
复制文件共耗时:9毫秒