converting byte[] to string

后端 未结 5 1080
[愿得一人]
[愿得一人] 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:39

    Is it actually encoded text? If so, specify the encoding.

    However, the data you've got doesn't look like it's actually meant to be text. It just looks like arbitrary binary data to me. If it isn't really text, I'd recommend converting it to hex or base64, depending on requirements. There's a good public domain base64 encoder you can use.

    String text = Base64.encodeBytes(byteArray);
    

    And decoding:

    byte[] data = Base64.decode(text):
    

提交回复
热议问题