learning java FileReader

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.nio.charset.Charset;

public class FileReaderTest {
    public static void main(String[] args) {
        try {
            var fr = new FileReader("FileReaderTest.java");
            {
                var cbuf = new char[1024];
                var hasRead = 0;
                while ((hasRead = fr.read(cbuf)) > 0){
                    System.out.println(new String(cbuf, 0, hasRead));
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

 

posted @ 2019-08-05 13:11  嵌入式实操  阅读(128)  评论(0编辑  收藏  举报