一、1,UTF编码 - 2,ISO解码 - 3,UTF编码 - 4,ISO解码
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解码
System.out.println(string);
//结果为6个"?"
bytes = string.getBytes(UTF);
//3,UTF编码
for(byte b : bytes)
System.out.print(b + " ");
//-61 -92 -62 -67 -62 -96 -61 -91 -62 -91 -62 -67(6个?编码为12个UTF)
string = new String(bytes,ISO);
//4,ISO解码
System.out.println("结果:"+string);
//结果:?¤??????????
二、1,UTF编码 - 2,GBK解码 - 3,UTF编码 - 4,GBK解码
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,GBK);
//2,GBK解码
System.out.println(string);
//浣犲ソ
bytes = string.getBytes(UTF);
//3,UTF编码
for(byte b : bytes)
System.out.print(b + " ");
//-26 -75 -93 -25 -118 -78 -29 -126 -67
string = new String(bytes,GBK);
//4,GBK解码
System.out.println(string);
//娴g姴銈?
三、1,GBK编码 - 2,UTF解码 - 3,UTF编码 - 4,GBK解码
String UTF = "UTF-8";
String GBK = "GBK";
String string = "你好";
byte[] bytes = string.getBytes(GBK);
//1,GBK编码
for(byte b : bytes)
System.out.print(b + " ");
//-60 -29 -70 -61
string = new String(bytes,UTF);
//2,UTF解码
System.out.println("结果:"+string);
//结果:3个"?"
bytes = string.getBytes(UTF);
//3,UTF编码
for(byte b : bytes)
System.out.print(b + " ");
//-17 -65 -67 -17 -65 -67 -17 -65 -67(已变)
string = new String(bytes,GBK);
System.out.println("结果:"+string);
//结果:锟斤拷锟?