java中的缓冲流也叫高效流,是对4个基本File流的增强,所以也是四个流。
字节缓冲流:BufferInputStream,BufferOutPutStream。
字符缓冲流:BufferedReader,BufferWriter;
字节缓冲流
使用步骤:
1:创建FileOutPutStream对象,构造方法中绑定要输出的目的地。
2:创建BufferOutPutStream对象,构造方法中传递FileOutPutStream对象,提高FileOutPutStream效率。
3:调用BufferOutPutStream对象中的write方法,把数据写到内存缓冲区
4:使用BufferOutPutStream对象中的flush方法把缓冲区数据刷新到文件中。
public class BufferO {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileOutputStream fos = new FileOutputStream("E:\\图片\\a.txt");
BufferedOutputStream bos = new BufferedOutputStream(fos);
bos.write("today is good day".getBytes());
bos.flush();
bos.close();
}
}
字节缓冲流复制。
public class BufferI {
@SuppressWarnings("resource")//去掉警告信息
public static void main(String[] args) throws IOException {
long start = System.currentTimeMillis()