UTF-8转GBK--->小试

来源:互联网 发布:民间山野怪谈前传 知乎 编辑:程序博客网 时间:2024/05/14 10:42

 package com.itheima.exam1.io;

import java.io.*;

public class InputStreamReaderDemo
{

    /**
     * @throws IOException
     * @param args
     * @throws
     */
    public static void main(String[] args) throws IOException
    {     //读取一个UTF_8的文件
        InputStreamReader in = new InputStreamReader(new FileInputStream(
                "D:\\2.txt"), "UTF-8");
            //以GBK存储文件
        OutputStreamWriter buffw = new OutputStreamWriter(new FileOutputStream(
                "D:\\5.txt"), "gbk");
        char[] buf = new char[1024];
        int len = 0;
        while ((len = in.read(buf)) != -1)
        {
            buffw.write(buf,0,len);
            buffw.flush();
        }
        in.close();
        buffw.close();

    }

}



0 0