一、字节流复制图片
public class Copy {
public static void main(String[] args) throws IOException {
FileInputStream fis = new FileInputStream("test.jpg");
FileOutputStream fos = new FileOutputStream("test_copy.jpg");
byte[] b = new byte[1024];
int len;
while ((len = fis.read(b))!=‐1) {
fos.write(b, 0 , len);
}
fos.close();
fis.close();
}
}
二、字节缓冲流复制
public static void bufferedByteTest() throws IOException{
long start = System.currentTimeMillis();
BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("yuan.jpg"));
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("copy.jpg"));
int len;
byte[] bytes = new byte[1024];
while ((len = bufferedInputStream.read(bytes)) != -1){
bufferedOutputStream.write(bytes,0,len);
}
System.out.println("耗时:" + (System.currentTimeMillis() - start));
bufferedOutputStream.close();
bufferedInputStream.close();
}