byte[]为参数新建一个String对象

一直都默认的认为

String(byte[] data) 可行的,其实还是含有隐患,今天查了一下接口发现:

 

String(byte[] data)
Converts the byte array to a string using the system's default charset.
是采用默认的charset
 
This is determined during VM startup, and will not change thereafter. On Android, the default charset is UTF-8.
 
所以隐患是如果移植到其他系统,可能会有问题,应该指定一个charset
 
String(byte[] data, String charsetName)
Converts the byte array to a string using the named charset.
posted @ 2013-05-18 10:57  JustinYo  阅读(509)  评论(0编辑  收藏  举报