java 多重_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编码)*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值