Converting a set of strings to a byte[] array

前端 未结 6 1078
甜味超标
甜味超标 2021-01-23 04:45

I am tring to convert a set of strings to a byte[] array. At first, I do something like this to convert a byte array to a string:

public String convertByte(byte[         


        
6条回答
  •  庸人自扰
    2021-01-23 05:42

    I don't understand why you are trying to get those bytes by characters. getBytes() and its variants will give you a byte[] array for whole string at once. However, if you want to see how characters are encoded, your approach my be good, but you have to keep in mind, that one character could be encoded in e.g. one to four bytes in some encodings, thus you need a byte array for every character.

提交回复
热议问题