Java实现转换文件的编码

将GBK编码的文本文件,转换成UTF-8编码的文本文件。

package com.fgy.demo;

import java.io.*;

public class Demo05Test {
    public static void main(String[] args) throws IOException {
        InputStreamReader isr = new InputStreamReader(new FileInputStream("d:\\GBK.txt"), "gbk");
        OutputStreamWriter osw = new OutputStreamWriter(new FileOutputStream("d:\\UTF-8.txt"), "utf-8");
        int len = 0;
        char[] chars = new char[1024];
        while ((len = isr.read(chars)) != -1) {
            osw.write(chars,0, len);
        }
        osw.close();
        isr.close();
    }
}

猜你喜欢

转载自www.cnblogs.com/roadlandscape/p/12168722.html