JAVA字符流中的编码解码问题2。144

InputStreamReader 是字节流到字符流的桥梁

OutputStreamWriter 是字符流到字节流的桥梁

 1     import java.io.*;
 2     
 3     public class ConversionstreamDemo {
 4         public static void main(String[] args) throws IOException {
 5             OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("./1.txt"),"GBK");
 6             osw.write("中国");
 7             osw.close();
 8     
 9             //字符输入流可以查看指定编码内容
10     
11             InputStreamReader isr = new InputStreamReader(new FileInputStream("./1.txt"),"GBK");
12             int ch;
13             while ((ch=isr.read())!=-1){
14                 System.out.print((char)ch);
15             }
16     
17         }
18     }

 

 
posted @ 2022-03-30 21:10  phpwyl  阅读(26)  评论(0编辑  收藏  举报