public class FileReaderTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
new FileReaderTest().readChar("d:\\JAVA之路.txt");
}
public void readChar(String filePath){
File file = new File(filePath);
FileReader fr = null;
int c;
try {
fr = new FileReader(file);
while(( c = fr.read()) != -1)
System.out.print((char)c);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
try {
fr.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
学习笔记 - 用FileReader读取文本文件并打印出来
最新推荐文章于 2021-02-27 14:45:05 发布