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();//关闭资源

    }
}

 

相关文章:

  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2021-06-18
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-11-20
  • 2021-06-25
  • 2021-10-21
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
相关资源
相似解决方案