java中字节数组转换为字符串

时间: 2023-07-11 admin 互联网

java中字节数组转换为字符串

java中字节数组转换为字符串

1、字节数组转换为字符串
byte[] byBuffer = new byte[20];
... ...
String strRead = new String(byBuffer);
strRead=String.copyValueOf(strRead.toCharArray(), 0, byBuffer.length]);
2、字符串转换成字节数组
byte[] byBuffer = new byte[200];
String strInput="abcdefg";
byBuffer= strInput.getBytes();