用 java 将文件的编码从GBK 转换成 UTF8

http://blog.csdn.net/laorer/archive/2009/02/08/3868962.aspx

 

非常好,解决了我的一个大问题。真是感谢。代码生成的java和jsp终于不再手工转码了。

 

核心代码:

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();
 }

 

将一个GBK编码的文件转成UTF8 编码的文件


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/laorer/archive/2009/02/08/3868962.aspx

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值