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的, 求解释,谢谢。

解决方案 »

  1.   

    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必出问题,不能互转。
      

  2.   

    一个以GBK编码的文件转成utf-8必出问题,不能互转。