java里面byte数组和String字符串怎么转换

如题所述

第1个回答  推荐于2016-06-17
//string 转 byte[]
String str = "问题";
byte[] srtbyte = str.getBytes();
// byte[] 转 string
String res = new String(srtbyte);
System.out.println(res);

//当然还有可以设定编码方式的
String str = "问题";
byte[] srtbyte = null;
try {
srtbyte = str.getBytes("UTF-8");
String res = new String(srtbyte,"UTF-8");
System.out.println(res);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}本回答被提问者和网友采纳
第2个回答  2015-02-11
new String(byte[] b, String charset)
相似回答
大家正在搜