文件的输入通过字符流(reader)

2018-05-23  本文已影响6人  Joy_yang17
public class FileInputReader {
     public static void main(String[] args) {
       File file = new File("learn.txt");
       try {
        FileInputStream fis = new FileInputStream(file);
        //把字节流转化成字符流
        InputStreamReader fir = new InputStreamReader(fis);
        char c [] = new char[1024];
        int l = 0;
        while ((l = fir.read(c)) != -1) {
            System.out.println(new String(c,0,l));
        }
        fis.close();
        fir.close();
    }  
       catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }   
    }
}
上一篇 下一篇

猜你喜欢

热点阅读