1、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);
//結果:?¤??????????spa
2、1,UTF編碼 - 2,GBK解碼 - 3,UTF編碼 - 4,GBK解碼get
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姴銈?string
3、1,GBK編碼 - 2,UTF解碼 - 3,UTF編碼 - 4,GBK解碼co
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);
//結果:錕斤拷錕?new