String str = new String("时之沙");
byte bytes[] = str.getBytes("GBK");
byte byte2[] = str.getBytes("ISO-8859-1");
String str_gbk = new String(bytes, "GBK");
System.out.println("str_gbk:" + str_gbk);
String str_utf8 = new String(bytes, "UTF-8");
System.out.println("str_utf8:" + str_utf8);
String str_iso8859 = new String(bytes, "ISO-8859-1");
System.out.println("str_iso8859" + str_iso8859);
String byte2_gbk = new String(byte2, "GBK");
System.out.println("byte2_gbk:" + byte2_gbk);
输出结果:
| str_gbk:时之沙 str_utf8:ʱ֮ɳ str_iso8859ʱ֮ɳ byte2_gbk:??? |
本文详细介绍了如何使用Java将字符串转换为不同编码(GBK, ISO-8859-1, UTF-8),并展示了编码转换后的输出结果。

265

被折叠的 条评论
为什么被折叠?



