eclipse原gbk工程改utf-8 乱码解决办法

lzqlawrence 2015-08-19

package test;

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

import org.apache.commons.io.FileUtils;


public class TransGbkToUtf8 {

	/**
	 * <Description>
	 *
	 * @since 2015-8-19
	 * @param args <Description>
	 * @throws Exception 
	 *
	 */
	public static void main(String[] args) throws Exception {
		//GBK编码格式源码路径 
		String srcDirPath = "E:\\RTC4.0.6\\workspace\\notify-api\\src"; 
		//转为UTF-8编码格式源码路径 
		String utf8DirPath = "E:\\RTC4.0.6\\workspace\\notify-api\\src1"; 
		        
		//获取所有java文件 
		Collection<File> javaGbkFileCol =  FileUtils.listFiles(new File(srcDirPath), new String[]{"java"}, true); 
		        
		for (File javaGbkFile : javaGbkFileCol) { 
		      //UTF8格式文件路径 
		      String utf8FilePath = utf8DirPath+javaGbkFile.getAbsolutePath().substring(srcDirPath.length()); 
		       //使用GBK读取数据,然后用UTF-8写入数据 
		      FileUtils.writeLines(new File(utf8FilePath), "UTF-8", FileUtils.readLines(javaGbkFile, "GBK"));        
		}
	}

}

相关推荐

谁在哀伤望月 / 0评论 2013-06-04
干货集合 / 0评论 2018-11-15