utf8字符编码格式转换gbk

public String utf8ToGBK(String f1, String f2) {
  String line = "";
  if ((null == f1) || (null == f2)) {
   return "";
  }
  try {
     BufferedReader in = new BufferedReader(new InputStreamReader(
     (new FileInputStream(f1)), "utf-8"));
    PrintWriter out = new PrintWriter(new OutputStreamWriter(
     (new FileOutputStream(f2)), "gbk"));

   while (null != (line = in.readLine())) {

    out.write(new String(line.getBytes(), "gbk") + "/n");

   }

   in.close();
   out.close();
   } catch (Exception e) {
   e.printStackTrace();

  }
  return line;
 } 

 

posted @ 2017-10-25 22:07  西瓜芝麻  阅读(1167)  评论(0编辑  收藏  举报