首页 > 其他 > 详细

String 和 byte[]

时间:2016-08-05 19:42:44      阅读:180      评论:0      收藏:0      [点我收藏+]

使用默认字符集合

Encodes this String into a sequence of bytes using the platform‘s default charset, storing the result into a new byte array. 

public byte[] getBytes()

Constructs a new String by decoding the specified array of bytes using the platform‘s default charset.

public String(byte bytes[])

 

默认字符集合

System.out.println(Charset.defaultCharset());

 

使用指定的字符集合

public byte[] getBytes(String charsetName)

Constructs a new String by decoding the specified array of bytes using the specified charset.

public String(byte bytes[], String charsetName)

 

字符集合不相同时会导致看到的字符串不一致,请确保字符集合相同。

小样:

byte[] bytes = "字符串".getBytes("utf-8");
System.out.println(new String(bytes,"utf-8"));// 字符串 

 

String 和 byte[]

原文:http://www.cnblogs.com/zno2/p/4626727.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!