s-day10-字节缓冲流一次读写一个字节数组的方式复制文件
This commit is contained in:
@@ -0,0 +1,29 @@
|
|||||||
|
package com.inmind.buffered01;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
|
||||||
|
/*
|
||||||
|
字节缓冲流一次读写一个字节数组的方式复制文件
|
||||||
|
*/
|
||||||
|
public class Demo02 {
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
//创建字节缓冲输入输出流
|
||||||
|
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("2.jpg"));
|
||||||
|
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("3.jpg"));
|
||||||
|
//一次读写一个字节数组,
|
||||||
|
byte[] bytes = new byte[1024];
|
||||||
|
long start = System.currentTimeMillis();
|
||||||
|
int len;
|
||||||
|
while ((len = bis.read(bytes)) != -1) {
|
||||||
|
bos.write(bytes, 0, len);
|
||||||
|
}
|
||||||
|
long end = System.currentTimeMillis();
|
||||||
|
System.out.println("复制所用时间:"+(end - start));//3ms
|
||||||
|
|
||||||
|
bis.close();
|
||||||
|
bos.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user