IO流6 --- FileReader中使用read(char[] cbuf)读入数据 --- 技术搬运工(尚硅谷)
- FileReader 字符输入流
@Test
public void test2(){
File file = new File("hello.txt");
FileReader fr = null;
try {
fr = new FileReader(file);
char[] cbuf = new char[5];
//返回读取的长度
int len;
while ((len = fr.read(cbuf)) != -1){
String str = new String(cbuf, 0, len);
System.out.print(str);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally {
if (fr != null){
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

浙公网安备 33010602011771号