转换流:把字节流转换为一个字符流

可以有效避免乱码的问题

例子

  1. import java.io.*;
  2. public class Main {
  3. public static void main(String[] args) throws Exception {
  4. String path = "./story.txt";
  5. boolean append = false;
  6. // 指定编码 GBK
  7. InputStreamReader isr = new InputStreamReader(new FileInputStream(path), "gbk");
  8. BufferedReader br = new BufferedReader(isr);
  9. String line = br.readLine();
  10. br.close();
  11. System.out.println("读取到的内容:" + line);
  12. }
  13. }