Java基础 read (char[] buffer) 底层原理

发布时间 2023-10-23 21:11:04作者: 嘎嘎鸭2
FileReader fr = new FileReader("E:\\Java基础资料\\a.txt");
char[] chars = new char[2];

while (true) {
int len = fr.read(chars);
if (len == -1)
break;
System.out.print(new String(chars, 0, len));
}

fr.close();

 

read (char[]  buffer) 方法:读取数据,解码,强转三步合并了,把强转之后的字符放到了字符数组当中,相当于空参的 read() 方法再加上强制类型转换