首页 > 编程语言 > 详细

批量 GBK 转 UTF8 java

时间:2014-04-02 11:48:35      阅读:429      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
package encoding;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.commons.io.FileUtils;

public class ChangeEncoding {
    public static void main(String[] args) throws IOException {
        // GBK编码格式源码路径
        String srcDirPath = "/Users/lumixraku/Documents/workspace/DisSys/src";
        // 转为UTF-8编码格式源码路径
        String utf8DirPath = "/Users/lumixraku/Documents/workspace/DisSys/src2";
        // 获取所有java文件
        Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(
                srcDirPath), new String[] { "java" }, true);

        for (File javaGbkFile : javaGbkFileCol) {
            System.out.println("File" + javaGbkFile.getAbsolutePath());
            // UTF8格式文件路径
            String utf8FilePath = utf8DirPath
                    + javaGbkFile.getAbsolutePath().substring(
                            srcDirPath.length());
            // 使用GBK读取数据,然后用UTF-8写入数据
            FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils
                    .readLines(javaGbkFile, "GBK"));
        }
    }
}
bubuko.com,布布扣

批量 GBK 转 UTF8 java,布布扣,bubuko.com

批量 GBK 转 UTF8 java

原文:http://www.cnblogs.com/cart55free99/p/3636718.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!