Hello,
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[] msg) {
String str = "";
for(int i = 0; i < msg.length; i++) {
str += (msg[i] + " * ");
}
return str;
}
When I try to convert back to the byte[] array, I don't get the same values as the ones when converted to a String. I originally had something gave me incorrect values.
I am currently trying something along the lines of:
public static byte[] convertStr(String ln)
{
System.out.println(ln);
String[] st = ln.split(" * ");
byte[] byteArray = new byte[23];
for(int i = 0; i < st.length; i++)
{
byteArray[i] = st[i].get byte value or something;
}
return byteArray;
}
If I try to use the getbytes() method from the String api, It returns a byte array rather than a byte and this is my problem.
Any help would be much appreciated.