Java source code garbled problem encoding converter, java source code
Note: Development Background: The Source Code imported to myeclipse is gbk encoding, and the project is UTF-8 encoding, leading to garbled source code check.
Zookeeper
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: 11:47:10 AM
*/
Public class Transcode {
/**
* @ Title: transcode
* @ Description: source code garbled Converter
* @ Param sourcePath source code path
* @ Param oldCode original encoding format of source code
* @ Param newCode the encoding format to be converted
* @ 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 <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/alisoft-xplatform-asf-cache-2.5.1-src/alisoft-xplatform-asf-cache-2.5.1-src", "GBK", "UTF-8", null );
}
}
Zookeeper