Java BufferedInputStream是通过缓冲数据向输入流添加功能,它维护一个内部缓冲区来存储从底层输入流中读取的字节。
我们可以通过FileInputStream来创造缓冲区输入流,代码如下:
String srcFile = "test.txt"; BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcFile));
Java BufferedInputStream用法示例:
import java.io.BufferedInputStream; import java.io.FileInputStream; /* www.tpyyes.com */ public class Main { public static void main(String[] args) { String srcFile = "test.txt"; try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream( srcFile))) { // 读取并输出文件数据 byte byteData; while ((byteData = (byte) bis.read()) != -1) { System.out.print((char) byteData); } } catch (Exception e2) { e2.printStackTrace(); } } }