JAVA—递归改工程编码
把以前学校机房的电脑写的代码拷贝到自己的电脑上发现乱码了,联系这几天学习的IO操作,自己写了一个字符转换代码。
需要用用到CommonsIO的组件(建议下载 jdk1.6)以上的版本
下载地址
将解压的这两个包添加的工程
对commons-io-2.6.jar BuildPath
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
public class EncodeChange02 {
public static void main(String[] args) throws IOException {
File src = new File("D:\\PINKMAN\\提交代码备份\\RSSReader");
recursion(src);
}
public static void recursion(File file) throws IOException {
if (null != file && file.isDirectory()) {
File[] files = file.listFiles();
for (File tempfile : files) {
if (tempfile.isFile()) {// tempfile.getAbsolutePath().substring(18)的作用是除去“D:\\PINKMAN\\提交代码备份\\”字符串
String msg = FileUtils.readFileToString(tempfile, "GBK");
FileUtils.writeStringToFile(new File("D:\\PINKMAN\\" + tempfile.getAbsolutePath().substring(18)),
msg, "utf-8");//指定写出文件的编码
System.out.println(tempfile);
}
recursion(tempfile);
}
}
}
}