發現各種編碼輸出的字節數組都不會變,為什么呢
public?class?Test?{
public?static?void?main(String?[]?args)?throws?Exception{
String?str?=?"怒罵ABC";
byte?[]?byte1?=?str.getBytes("gbk");//編碼格式為項目默認,即utf-8
for(byte?b?:?byte1)?{
System.out.print(Integer.toHexString(b?&?0xff)?+?"?");?//中文兩個字節,英文一個
}
System.out.println();
byte?[]?byte2?=?str.getBytes("gb2312");
for(byte?b?:?byte1)?{
System.out.print(Integer.toHexString(b?&?0xff)?+?"?");
}
}
}
添加回答
舉報
0/150
提交
取消