Java文件处理之FileReader可输出中文字符

import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class FileReaderDemo1 {
    public static void main(String[] args) throws IOException {
        //使用文件名创建流对象
        FileReader fr = new FileReader("a.txt");
        //定义一个变量,保存数据
        int c;
        while ((c=fr.read())!=-1){//每次读取一个字符
            System.out.println((char)c);//可输出中文字符
        }

//        char[] charBuff = new char[2]; 
//        while ((len=fr.read(charBuff))!=-1){//每次读取两个字符
//            System.out.println(new String(charBuff));
//
//        }

        fr.close();//关闭资源

    }
}
忘了他,我撸代码养你
原文地址:https://www.cnblogs.com/theworld/p/11641937.html