字符缓冲输入流读数据 1216

时间:2022-12-16 16:57:42
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Test2 {
public static void main(String[] args) throws IOException {
// 召唤一个真正可读的对象
FileReader fRead = new FileReader("缓冲写数据.txt");
// 实例化字符缓冲输入流
BufferedReader bufferedReader = new BufferedReader(fRead);
// 读数据(遍历读完所有)
char[] chars = new char[5];
int len = bufferedReader.read(chars);
while (len != -1) {
// 输出数据
String msg = new String(chars, 0, len);
System.out.print(msg);
// 重新读一下
len = bufferedReader.read(chars);
}
// 关资源
bufferedReader.close();
fRead.close();
// 程序结束
System.out.println("game over");
}
}