如何将byte数组转换成string字符
1个回答
展开全部
1、string 转 byte[]
String str = "Hello";
byte[] srtbyte = str.getBytes();
2、byte[] 转 string
byte[] srtbyte;
String res = new String(srtbyte);
System.out.println(res);
3、设定编码方式相互转换
String str = "hello";
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();
}
String str = "Hello";
byte[] srtbyte = str.getBytes();
2、byte[] 转 string
byte[] srtbyte;
String res = new String(srtbyte);
System.out.println(res);
3、设定编码方式相互转换
String str = "hello";
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();
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询