converting byte[] to string

后端 未结 5 961
[愿得一人]
[愿得一人] 2021-01-13 02:51

I am having a bytearray of byte[] type having the length 17 bytes, i want to convert this to string and want to give this string for another comparison but the output i am g

5条回答
  •  一整个雨季
    2021-01-13 03:36

    not 100% sure if I get you right. Is this what you want?

    String s = null;
    StringBuffer buf = new StringBuffer("");
    byte[] byteArray = new byte[] {0,127,-1,-2,-54,123,12,110,89,0,0,0,0,0,0,0,0};
    for(byte b : byteArray) {
      s = String.valueOf(b);
      buf.append(s + ",");
    }
    String value = new String(buf);
    System.out.println(value);
    

提交回复
热议问题