当前位置: 代码迷 >> Web前端 >> 一个GBK编码的资料转成UTF8编码的文件
  详细解决方案

一个GBK编码的资料转成UTF8编码的文件

热度:101   发布时间:2012-10-12 10:17:04.0
一个GBK编码的文件转成UTF8编码的文件
private static void transferFile(String srcFileName, String destFileName) throws IOException {
  String line_separator = System.getProperty("line.separator"); 
  FileInputStream fis = new FileInputStream(srcFileName);
  StringBuffer content = new StringBuffer();
  DataInputStream in = new DataInputStream(fis);
  BufferedReader d = new BufferedReader(new InputStreamReader(in, "GBK"));// , "UTF-8"  
  String line = null;
  while ((line = d.readLine()) != null)
   content.append(line + line_separator);
  d.close();
  in.close();
  fis.close();
      
  Writer ow = new OutputStreamWriter(new FileOutputStream(destFileName), "utf-8");
  ow.write(content.toString());
  ow.close();
 }
  相关解决方案