当前位置: 代码迷 >> J2SE >> 请教怎么把一个字节数组(内容为ASCII字符)转换为一个字符串
  详细解决方案

请教怎么把一个字节数组(内容为ASCII字符)转换为一个字符串

热度:246   发布时间:2016-04-24 17:09:58.0
请问如何把一个字节数组(内容为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);
}

}

建了个静态方法,方便使用~~~~
  相关解决方案