1.1概述:
1.2字节缓冲输出流:BufferedOutputStream
package com.zhs.io;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class DemoBfferOut {
public static void main(String[] args) throws IOException {
//创建文件输出流对象,绑定目的地址
FileOutputStream fos=new FileOutputStream("E:\\JavaBase\\FirstPro\\src\\a.txt");
//创建缓冲输出流对象,提高文件输出流效率
BufferedOutputStream bos= new BufferedOutputStream(fos);
//写入字符串内容到缓冲区
bos.write("今天天气不错啊?".getBytes());
bos.flush();//刷新到文件中
bos.close();//释放资源
}
}
1.3字节缓冲输出流:BufferedInputStream
public static void main(String[] args) throws IOException {
FileInputStream fis=new FileInputStream("E:\\JavaBase\\FirstPro\\src\\a.txt");
BufferedInputStream bis=new BufferedInputStream(fis);
int len=0;
while ((len=bis.read())!=-1){
System.out.println(len);
}
bis.close();//释放资源
// fis.close();
}
public static void main(String[] args) throws IOException {
FileInputStream fis=new FileInputStream("E:\\JavaBase\\FirstPro\\src\\a.txt");
BufferedInputStream bis=new BufferedInputStream(fis);
int len=0;
byte[] bytes=new byte[1024];
while ((len=bis.read(bytes))!=-1){
System.out.println(new String(bytes,0,len));
}
bis.close();//释放资源
// fis.close();
}