JavaSE 高级 第14节 读文件类FileReader
2016-07-24
InputStreamReader :
FileInputStream fis=new FileInputStream(file);
InputStreamReader isr=new InputStreamReader(fis);
FileReader:
FileReader fr=new FileReader("C:\\Users\\admin\\Desktop\\in.txt");
1,FileReader
package com.java1995; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class TestFileReader { public static void main(String[] args) { FileReader fr=null; System.out.println( System.getProperty("file.encoding")); try { fr=new FileReader( "D:\\workspace\\java_io\\in.txt"); int c=0; c=fr.read(); while(c!=-1){ System.out.print((char)c); c=fr.read(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }finally{ //关闭流 } } }
【参考资料】