例如我的byte[]是26292032363这样的一个数字串,而我怎么可以将它转换成string也是“26292032363”呢?我用String.valueOf(byte[])转回来的不是我想要的,我要怎么做呢?

解决方案 »

  1.   

    String str = new String(bys);
      

  2.   


    String s = new String(<byte array>)
      

  3.   


    public class Test {
    public static void main(String[] args) throws UnsupportedEncodingException {
    byte[] bs = {2, 6, 2, 9, 2, 0, 3, 2, 3, 6, 3};
    String s = "";
    for(byte b : bs)
    s += b;
    System.out.println(s);
    }
    }
      

  4.   

    那要看你的byte[]中一个字节存了什么样的数?如果是ASCII码,则直接new String(byte[])就可以,但如果是数字,就要经过一番计算,应该是右移8位相加吧
      

  5.   

    按楼主的意思应该可以这样:public class testByte {
    public static void main(String[] args){
    byte[] bt={1,2,3,4};
    String str="";
    for(int i=0;i<bt.length;i++){
    str=str+bt[i];
    }
    System.out.println(str.toString());
    }
    }
      

  6.   

    public class Test { public static void main(String[] args) throws UnsupportedEncodingException { byte[] bs = {2, 6, 2, 9, 2, 0, 3, 2, 3, 6, 3}; String s = ""; for(byte b : bs) s += b; System.out.println(s); } }