java编码-多重(正常)

String ISO = "ISO-8859-1";
String UTF = "UTF-8";
String GBK = "GBK";
String string = "你好";
byte[] bytes = string.getBytes(UTF);
//1,UTF编码
for(byte b : bytes)
System.out.print(b + " ");
//-28 -67 -96 -27 -91 -67
string = new String(bytes,ISO);
//2,ISO解码
//结果为6个"?"
/*解释:ISO编码范围是0x00-0xFF,不认识负数,故解码后为?*/
System.out.println("结果:"+string);
bytes = string.getBytes(ISO);
//3,ISO编码
for(byte b : bytes)
System.out.print(b + " ");
//-28 -67 -96 -27 -91 -67(不变)
string = new String(bytes,UTF);
//4,UTF编码
System.out.println("结果:"+string);
//结果:你好
/*解析:由UTF编码至UTF编码,中间多了两步(即ISO解码和ISO编码)*/

posted @ 2017-12-29 13:43  wonkju  阅读(285)  评论(0编辑  收藏  举报