![]()
package com.bjsxt.ios3;
import java.io.*;
/**
*1.只要关闭高层流即可,底层流不用手动关闭;因为高层的关闭方法就是把底层流关闭
*
*2.何时将输出缓冲区的内容写入硬盘
* 1.输出缓冲区满,自动写入硬盘(刷新 flush)
* 2.close()会先刷新
* 3.手动的flush()
* 3.缓冲流的原理
*/
public class TestBuffredStream2 {
public static void main(String[] args) throws IOException {
//1.创建流
// InputStream fis = new FileInputStream("e:/JDK_API_1_6_zh_CN.CHM");
// OutputStream fos = new FileOutputStream("e:\\JDK_API_1_6_zh_CN2.CHM");
// BufferedInputStream bis = new BufferedInputStream(fis);//8192
// BufferedOutputStream bos = new BufferedOutputStream(fos);//8192
BufferedInputStream bis =
new BufferedInputStream(new FileInputStream("e:/JDK_API_1_6_zh_CN.CHM"));//8192
BufferedOutputStream bos =
new BufferedOutputStream(new FileOutputStream("e:\\JDK_API_1_6_zh_CN2.CHM"));//8192
//2.使用流
//2.1 准备一个中转站(一个字节)
byte [] buf = new byte[1024];
//先读一个字节
int len= bis.read(buf);//读源文件的一个字节赋给n
while(len != -1){ //读到 了数据,还没有到文件末尾
//写一个字节
bos.write(buf,0,len);
//再读一个字节
len= bis.read(buf);//读源文件的一个字节赋给n
}
//3.关闭流
bos.flush();
bis.close();
bos.close();
// fis.close();
// fos.close();
}
}