String(byte[] bytes, String charsetName)

时间:2023-03-08 19:22:17
  1. String str = new String("时之沙");
  2. byte bytes[] = str.getBytes("GBK");
  3. byte byte2[] = str.getBytes("ISO-8859-1");
  4. String str_gbk = new String(bytes, "GBK");
  5. System.out.println("str_gbk:" + str_gbk);
  6. String str_utf8 = new String(bytes, "UTF-8");
  7. System.out.println("str_utf8:" + str_utf8);
  8. String str_iso8859 = new String(bytes, "ISO-8859-1");
  9. System.out.println("str_iso8859" + str_iso8859);
  10. String byte2_gbk = new String(byte2, "GBK");
  11. System.out.println("byte2_gbk:" + byte2_gbk);
  12. 输出结果:

    str_gbk:时之沙
    str_utf8:ʱ֮ɳ
    str_iso8859ʱ֮ɳ
    byte2_gbk:???