学习笔记 - 用FileReader读取文本文件并打印出来

来源:互联网 发布:淘宝全屏海报加热点 编辑:程序博客网 时间:2024/06/03 02:47
public class FileReaderTest {public static void main(String[] args) {// TODO Auto-generated method stubnew 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 blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} finally{try {fr.close();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}}}}

0 0