public static void main(String[] args) throws IOException {
//场景: 从磁盘的C:/aaa/1.txt文件 将数据读取到Java代码中赋值给一个变量。
//1.创建File对象, 就是数据源
File file = new File("c:/aaa/1.txt");
//2.创建字节输入流对象,操作数据源对象
FileInputStream fis = new FileInputStream(file);
//3.FileInputStream 流对象本身不具备缓冲功能!!!
//A BufferedInputStream为另一个输入流添加了功能,即缓冲输入
BufferedInputStream bis = new BufferedInputStream(fis);
//4.走到这一步,字节输入流就具备缓冲功能了
//当创建BufferedInputStream时,将创建一个内部缓冲区数组。
byte[] buf = new byte[3];//缓冲数组。现在是空的数组
System.out.println("Line24:"+new String(buf));
//每次需要从1.txt文件中读取3个字节 到 空的数组中
//为啥是字节数组,因为字节流
//5.开始从1.txt文件中 去读取数据放到数组中
//从输入流读取一些字节数,并将它们存储到缓冲区b
int read = bis.read(buf);
//读取到缓冲区的总字节数,或者如果没有更多的数据,因为已经到达流的末尾,则是 -1 。
System.out.println(read);//3
//缓冲数组中数据 咋看?
System.out.println("Line33:"+new String(buf, 0, read));//abc
int read1 = bis.read(buf);
System.out.println(read1);//1
System.out.println("Line35:"+new String(buf, 0, read1));
//第一次的时候: [a, b, c]
//第二次的时候: [d, b, c]
//6.关闭流
bis.close();
fis.close();
}