进阶day10-缓冲流的介绍

This commit is contained in:
2026-03-21 16:31:32 +08:00
parent e50b2e7b8a
commit e03cf2327c

View File

@@ -0,0 +1,36 @@
package com.inmind.buffered_stream01;
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
/*
4个流本身是没有读写功能都是基于昨天的字节流和字符流进行操作所以今天只要先区分到底是什么流然后就调用对应流的api
缓冲流基于字节字符流它本身是没有读写功能底层封装了一个8192长度的缓冲区数组提高读写效率也叫高效流(空间换时间)
字节缓冲流BufferedInputStream BufferedOutputStream
字符缓冲流BufferedReader BufferedWriter
------------------------------------------------------------------------------------------------
字节缓冲流的基本使用以及使用缓冲流复制文件(一次读写一个字节)
字节缓冲输入流BufferedInputStream
构造方法:
BufferedInputStream(InputStream in) 创建一个 BufferedInputStream并保存其参数输入流 in供以后使用。
常用方法:
int read() :读取一个字节数据
int read(byte[] bytes) 读取一个字节数组
*/
public class Demo01 {
public static void main(String[] args) throws Exception {
//IO流的操作
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("a.txt"));
//读取a.txt中的字节数据
int b ;//接收读取到的字节数据
while ((b = bis.read()) != -1) {
System.out.println((char) b);
}
bis.close();
}
}