ITeye博客

JAVA的字符编码问题,错误解码,再编码,再正确解码,出来是乱码

kiol · 2009-02-05 08:57 · Markdown

示例代码如下: /*

  • To change this template, choose Tools | Templates
  • and open the template in the editor. */ package javacharsettest;

import java.io.UnsupportedEncodingException;

/** *

  • @author jiayp */ public class Main {

    /**

    • @param args the command line arguments */ public static void main(String args) { // TODO code application logic here try { String str = "a你好b"; str = new String(str.getBytes("GBK"), "UTF-8"); str = new String(str.getBytes("UTF-8"), "GBK");

       System.out.print(str);
      

      }catch(UnsupportedEncodingException e){};

    } }

请问有办法把错误解码的字符串给还原回去吗?

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。