请问如何把一个字节数组(内容为ASCII字符)转换为一个字符串?
C#中有如下方法,java中呢?
byte[] x = new byte[4]{49,50,51,52};
String str = System.Text.Encoding.ASCII.GetString(x);
//现在str = “1234”;
------解决方案--------------------帮顶
------解决方案--------------------byte[] x = new byte[]{49,50,51,52};
System.out.println(new String(x));
------解决方案--------------------byte[] x = new byte[]{49,50,51,52};
String str = new String(x);
------解决方案--------------------package testString;
public class ASCToString {
public static String ascToString(byte[] cs){
String s;
return s = new String(cs);
}
}
建了个静态方法,方便使用~~~~