public static void main(String[] args){
try {
// 以下 是 普通货物 的UTF-8 字节
byte[] data = new byte[] {-26, -103, -82, -23, -128, -102, -24, -76, -89, -25, -119, -87};
new String(data,"UTF-8");
String u = new String(data,"UTF-8");
System.out.println(u);
byte[] uc = u.getBytes("UTF-8");
for(int i =0 ;uc.length>i;i++) {
System.out.print("\t"+(new Integer(uc[i])).toString() + ",");
}
System.out.println("");
String a = new String(data,"GBK");
byte[] c = a.getBytes("GBK");
for(int i =0 ;c.length>i;i++) {
System.out.print("\t"+(new Integer(c[i])).toString() + ",");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
那么 为何 乱码 GBK 却不能把 字节还原回去
try {
// 以下 是 普通货物 的UTF-8 字节
byte[] data = new byte[] {-26, -103, -82, -23, -128, -102, -24, -76, -89, -25, -119, -87};
new String(data,"UTF-8");
String u = new String(data,"UTF-8");
System.out.println(u);
byte[] uc = u.getBytes("UTF-8");
for(int i =0 ;uc.length>i;i++) {
System.out.print("\t"+(new Integer(uc[i])).toString() + ",");
}
System.out.println("");
String a = new String(data,"GBK");
byte[] c = a.getBytes("GBK");
for(int i =0 ;c.length>i;i++) {
System.out.print("\t"+(new Integer(c[i])).toString() + ",");
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
那么 为何 乱码 GBK 却不能把 字节还原回去