用Java程序进行编码转换

来源:互联网 发布:sd格式化数据恢复 编辑:程序博客网 时间:2024/05/21 21:28


先导入commons-io-2.4.jar这个包,下载地址 http://commons.apache.org/proper/commons-io/download_io.cgi


程序如下:


import java.io.File;import java.io.IOException;import java.util.Collection;import org.apache.commons.io.FileUtils;public class Transcoding {public static void main(String[] args) throws IOException {//GBK编码格式源码路径String srcDirPath="E:\\workspace_android\\MyISchedule\\src";//转为UTF-8编码格式源码路径String utf8DirPath="E:\\src";//获取所有java文件 Collection<File> javaGbkFiles=FileUtils.listFiles(new File(srcDirPath), new String[]{"java"}, true);for(File javaGbkFile : javaGbkFiles){//UTF8格式文件路径String utf8FilePath=utf8DirPath+javaGbkFile.getAbsolutePath().substring(srcDirPath.length());//使用GBK读取数据,然后用UTF-8写入数据 FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile,"GBK"));}}}


0 0
原创粉丝点击