java编码-多重(乱码)
一、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);
//結果:錕斤拷錕?
轉載于:https://www.cnblogs.com/listened/p/8144212.html
總結
以上是生活随笔為你收集整理的java编码-多重(乱码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 静态与动态库文件
- 下一篇: qrcode——js生成二维码