首页 > 代码库 > 常用编码测试

常用编码测试

 1 public static void main(String[] args) { 2         String s = "你好"; 3         String cn = ""; 4         System.out.println("src: " + s); 5          try { 6               7             byte[] bs = s.getBytes("utf-8"); 8             System.out.println(Arrays.toString(bs));; 9             //[-28, -67, -96, -27, -91, -67]10             cn = new String(bs, "utf-8");11             System.out.println(cn);12             //你好13             cn = new String(bs, "gbk");14             System.out.println(cn);15             //浣犲ソ16             17             bs = s.getBytes("gbk");18             System.out.println(Arrays.toString(bs));19             //[-60, -29, -70, -61]20             21             cn = new String(bs, "gbk");22             System.out.println(cn);23             //你好24             cn = new String(bs, "utf-8");25             System.out.println(cn);26             //???27         } catch (UnsupportedEncodingException e) {28             e.printStackTrace();29         }30     }