zoukankan      html  css  js  c++  java
  • OutputStreamWriter与InputStreamReader(转换流)的编码解码

    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.FileReader;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    import java.io.OutputStreamWriter;
    import java.io.UnsupportedEncodingException;
    
    public class TransStreamDemo {
    
        public static void main(String[] args) throws IOException {
            writerText_1();
            //writerText_2();
            //Reader_1();
            //Reader_2();
            
        }
    
        public static void Reader_2() throws IOException {
            InputStreamReader isr = new InputStreamReader(new FileInputStream("F:\gbk_1.java"),"utf-8");
            int ch = 0;
            while((ch=isr.read())!=-1){
                System.out.print((char)ch);
            }
        }
    
        public static void Reader_1() throws IOException {
            FileReader fr = new FileReader("F:\gbk_1.java");
            int ch = 0;
            while((ch=fr.read())!=-1){
                System.out.print((char)ch);
            }
            
        }
    
        public static void writerText_2() throws IOException {
            OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("F:\gbk_2.java"),"utf-8");//转换流可以指定编码表
            osw.write("你好");
            osw.close();
        }
    
        public static void writerText_1() throws IOException {
            FileWriter fw = new FileWriter("F:\gbk_1.java");//编码表固定的
            
            fw.write("你好");
            fw.flush();
            fw.close();
        }
    }
  • 相关阅读:
    [NOI2012] 美食节
    [NOI2008] 志愿者招募
    P3834 【模板】可持久化线段树 2(主席树)
    P3919 【模板】可持久化线段树 1(可持久化数组)
    P4168 [Violet]蒲公英
    轻重链剖分
    沉舟侧畔千帆过 病树前头万木春
    P2119 魔法阵 (0.1s 虐杀过程)
    两行虐杀儒略历
    CSP2020 S-2 爆零(日)记 (已完结)
  • 原文地址:https://www.cnblogs.com/LO-ME/p/3594228.html
Copyright © 2011-2022 走看看