java项目编码转换不产生乱码,Java源码乱码问题 编码转换器

41c3729b05658266238e00713094e535.gif

注释:开发背景:导入到myeclipse中的源码是gbk编码,项目是utf-8编码,导致查看源码乱码问题。



package com.test;

import java.io.File;

import java.io.IOException;

import java.util.Collection;

import org.apache.commons.io.FileUtils;

import org.junit.Test;

/**

*

* @FileName    : Transcode

* @Description : 文件编码转换器

* @Copyright   : XXXX

* @Company     : XXXXXX

* @author      : 星辰

* @version     : 1.0

* Create Date  : 2014-11-12 上午11:47:10

*/

public class Transcode {

/**

* @Title: transcode

* @Description: 源代码乱码转换器

* @param sourcePath 源代码路径

* @param oldCode 源代码原来的编码格式

* @param newCode 源代码需要转换成的编码格式

* @param extensions an array of extensions, ex. {"java","xml"}. If this parameter is null, all files are returned

* @return:void

*/

public void transcode(String sourcePath,String oldCode,String newCode,String[] extensions){

Collection javaGbkFileCol =  FileUtils.listFiles(new File(sourcePath), extensions, true);

for (File gbkFile : javaGbkFileCol) {

try {

FileUtils.writeLines(new File(gbkFile.getAbsolutePath()), newCode, FileUtils.readLines(gbkFile,oldCode));

} catch (IOException e) {

e.printStackTrace();

}

}

}

@Test

public void test(){

new Transcode().transcode("C:/Users/chx/Desktop/alisoft-xplatform-asf-cache-2.5.1-src资料/alisoft-xplatform-asf-cache-2.5.1-src资料/alisoft-xplatform-asf-cache-2.5.1-src","GBK","UTF-8",null);

}

}



原文:http://blog.csdn.net/chx10051413/article/details/41041031

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值