一部のjavaコードは鉦斤の拷問を知っています。


@Test
public void testKunJinKao(){
  String str="      ";
  try {
    byte[] buff=null;

    //             ,let's go

    //1.    GBK   ,    UTF-8,   UTF-8   ...
    buff=str.getBytes("GBK");//        ,         
    String str1=new String(buff,"UTF-8");
    System.out.println(str1);//      :���

    //2.    UTF-8   ,    GBK,   GBK   ...
    buff=str.getBytes("UTF-8");//        ,         
    String str2=new String(buff,"GBK");//     
    System.out.println(str2);//        :

    //    ,       ?come on

    //3.      GBK   ,                  UTF-8   
    String str3=new String(str.getBytes("GBK"),"UTF-8");
    String str4=new String(str3.getBytes("UTF-8"),"GBK");//              ,      。
    System.out.println(str4);//   

    /** * Got it.How are you,nice to meet you. * * Why? *      1、2         , *     3         ,     (       ),            。 */

    /** *        ,    1   ,     3   。       ,     1      UTF-8     ; *    3  GBK     。 */

    /** *     ,         ? * *   GBK    Unicode          。 * Unicode            ,      , Unicode      , * Unicode         (REPLACEMENT CHARACTER)       ,   :U+FFFD * * U+FFFD UTF-8    ,    '\xef\xbf\xbd'。 * *     ,   '\xef\xbf\xbd\xef\xbf\xbd', *     GBK/CP936/GB2312/GB18030        , *     2   ,       :   —— (0xEFBF), (0xBDEF), (0xBFBD)。 */
  } catch (Exception e) {
    e.printStackTrace();
  }


}