Note: The development background: Import into the MyEclipse source code is GBK encoding, the project is UTF-8 encoding, resulting in viewing the source code garbled problem.
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: File Encoding Converter
* @Copyright: XXXX
* @Company: XXXXXX
* @author: Stars
* @version: 1.0
* Create date:2014-11-12 11:47:10
*/
public class Transcode {
/**
* @Title: Transcode
* @Description: Source code garbled Converter
* @param sourcepath Source code path
* @param the original encoding format of Oldcode source code
* @param newcode Source code needs to be converted into an encoding format
* @param extensions an array of extensions, ex. {"Java", "xml"}. If This parameter was null, all files are returned
* @return: void
*/
public void Transcode (String sourcepath,string oldcode,string newcode,string[] extensions) {
collection<file> 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 profile/ ALISOFT-XPLATFORM-ASF-CACHE-2.5.1-SRC data/alisoft-xplatform-asf-cache-2.5.1-src "," GBK "," UTF-8 ", null);
}
}
Java source code garbled problem Encoding Converter