写了一个简易的GBK文件向UTF8文件转换的工具

package com.bocom.framework.util;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter; public class GBK2UTF8 { /**
* GBK文件转换为UTF-8文件
*
* @throws Exception
*/
public static void convert() throws Exception { File f = new File("D:\\Program Files\\workspace\\Plug_In_Interface_V1\\src\\com\\bocom\\framework\\util");
File files[] = f.listFiles(); for (File file : files) {
if (file.isDirectory()) {
continue;
}
FileInputStream in = new FileInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "gbk"));
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line);
sb.append("\r\n");
}
reader.close();
file.delete(); FileOutputStream out = new FileOutputStream(file);
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "utf-8"));
writer.write(sb.toString());
writer.close();
}
} public static void main(String[] arg) { try {
GBK2UTF8.convert();
} catch (Exception e) {
e.printStackTrace();
}
}
}

  

上一篇:自己写的一个抢票加速的Python小程序源码分享-----纯属娱乐


下一篇:node.js 如何处理一个很大的文件