Java中byte怎么转化为String

2019-12-05 18:48:49 浏览数 (1)

string转化为byte[]数组

代码语言:javascript复制
String str = "abcd";
byte[] bs = str.getBytes();

byte[]数组转化为string字符串

代码语言:javascript复制
/*String str1 = "abcd";
byte[] bs1 = str1.getBytes();*/
byte[] bs1 = {97,98,100};
String s = new String(bs1);

设置格式

代码语言:javascript复制
byte[] srtbyte = {97,98,98};
String res = new String(srtbyte,"UTF-8");

0 人点赞