项目编码格式修改,将项目中的GBK文件改为UTF-8文件
作者:互联网
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import org.apache.commons.io.FileUtils;
public class Test {
public static void main(String[] args) throws IOException {
//GBK编码格式源码路径
String srcDirPath = "E:\\test";
//转为UTF-8编码格式源码路径
String utf8DirPath = "E:\\UTF8\\test";
//获取所有java文件
Collection<File> javaGbkFileCol = FileUtils.listFiles(new File(srcDirPath), new String[]{"java","xml","jsp"}, 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"));
}
System.out.println("OK");
}
}
标签:文件,UTF,String,java,GBK,FileUtils,import 来源: https://blog.csdn.net/zy123698745/article/details/110529274