String ISO = "ISO-8859-1";
String UTF = "UTF-8";
String GBK = "GBK";
String string = "很开心分享经验";
/*ISO*/
byte[] bytes = string.getBytes(ISO);
System.out.println("结果:"+new String(bytes,ISO));
//結果为7个"?"
for(byte b:bytes)
System.out.print(b+" ");
//结果为7个"63"
/*解释:由于iso8859-1不认识中文字符,统统用63表示(该编码将"?"编码为"63"
* 而英文不涉及编码(英文用ASCII,而iso8859-1,utf8,GBK几种编码兼容ASCII)
* */
/*UTF*/
bytes = string.getBytes(UTF);
System.out.println("结果:"+new String(bytes,UTF));
//结果:很开心分享经验
for(byte b:bytes)
System.out.print(b+" ");
//结果为:-27 -66 -120 -27 -68 -128 -27 -65 -125 -27 -120 -122 -28 -70 -85 -25 -69 -113 -23 -86 -116
/*GBK(也正常)*/
bytes = string.getBytes(GBK);
System.out.println("结果:"+new String(bytes,GBK));
//遇到一大堆"?",一般可以确定用了ISO
/*其他类型编码:
1. 寰堝紑蹇冨垎浜粡楠? UTF-GBK
2. ?????????? GBK-UTF
3. oü?aD?·??í??é GBK-ISO
4. ?????€???????o????éa UTF-ISO
5 裥?菥袆???? utf-8--utf-16
* */