使用的开发环境是jbuilder 9,工程设置中ecoding选择utf8,代码如下:
    String  str = "中国";
    byte []buf  = new byte[str.getBytes().length];
    buf = str.getBytes("GBK");
     System.out.println(str);
    String str2 = new String(buf,"GBK");
    System.out.println(str2);
输出结果为乱码,请高手点评。
如果工程设置中ecoding使用GBK,则可以正确显示,也请说明原因。

解决方案 »

  1.   

    String  str = "中国";这一步,就是根据 你工程的编码 来决定 str 的编码的。
      

  2.   

    好象是 
    utf8使用的1-3个字节对字符进行编码,对在ACSII中出现的字符编码规制没变,而对其他的字符则使用2-3个字节进行编码,
    而GBK使用2个字节对字符进行编码
    如果你使用utf8对程序进行编译,在使用GBK存取字符,出现乱码是必然的
      

  3.   

    如果工程设置中ecoding选择utf8编码,如何才能正确显示呢?
      

  4.   

    String str2 = new String(buf,"GBK");去掉GBK