1.代码
代码语言:javascript
复制package d04_test;/*
* zt
* 2020/8/8
* 15:07
*使用缓冲字节流实现复制文件(BufferedInputStream)
*/
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class Demo1 {
public static void main(String[] args) throws Exception {
//1.创建缓冲字节流
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("e:\aaa.txt"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("e:\bbb.txt"));
//边读边写
byte[] buf = new byte[1024];
int len = 0;
while((len=bis.read(buf))!=-1){
bos.write(buf,0,len);
bos.flush();
}
bis.close();
bos.close();
System.out.println("复制好了");
}
}
运行结果
代码语言:javascript
复制复制好了