当前位置: 代码迷 >> J2SE >> 关于编码的疑问,感谢···
  详细解决方案

关于编码的疑问,感谢···

热度:6987   发布时间:2013-02-25 00:00:00.0
关于编码的疑问,求助,感谢···
[code=Java][/code]
public static void main(String[] args)throws Exception {
// TODO Auto-generated method stub
String s1 = "你好!";
byte[] b1 =s1.getBytes("GBK"); //国标编码.
System.out.println(Arrays.toString(b1));
String s2 =new String(b1,"utf-8"); //utf-8 解码.
System.out.println(s2);
byte[] b2 = s2.getBytes("utf-8");//utf-8编码.
//String s3= Arrays.toString(b2);
System.out.println(new String(b2,"GBK")); //国标编码.
}

请问:我知道用utf-8编码,再用utf-8解码的时候,所得的码已经不是原始的码,
请问,这该怎么优化呢?

初学java的, 求解释,谢谢。

------解决方案--------------------------------------------------------
Java code
public static void main(String[] args)throws Exception {        String s1 = "你好!";                byte[] b1 =s1.getBytes("GB2312"); //国标编码.        System.out.println(Arrays.toString(b1));                String s2 = new String(b1); //国标解码        System.out.println(s2);                    }
------解决方案--------------------------------------------------------
一个以GBK编码的文件转成utf-8必出问题,不能互转。
  相关解决方案