Io流之用缓冲流实现文件的复制
package Io流;
import org.junit.Test;
import java.io.*;
/**
* 磁盘,键盘------输入(读)------->程序-------输出(写)----->磁盘,键盘
* 缓冲流
* BufferedInputStream
* BufferedOutputStream
*/
public class Demo05 {
@Test
public void test(){
long startTime = 0;
long endTime = 0;
FileInputStream fis = null;
FileOutputStream fos = null;
BufferedInputStream bfis = null;
BufferedOutputStream bfos = null;
try {
startTime = System.currentTimeMillis();
fis = new FileInputStream("d:\\11.txt");
bfis = new BufferedInputStream(fis);
fos = new FileOutputStream("e:\\1.txt");
bfos = new BufferedOutputStream(fos);
byte[] bytes = new byte[1024];
int len = 0;
while ((len =bfis.read(bytes))!=-1 ){
bfos.write(bytes,0,len);
}
endTime = System.currentTimeMillis();
}catch (Exception e){
e.printStackTrace();
}finally {
try {
System.out.println(endTime-startTime);
bfos.close();
bfis.close();
fos.close();
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
人生不易,多多努力!!!
浙公网安备 33010602011771号