I have a file that is written in bytes, like this
\r\x00\x00\x00\xd0{"a": "test"}
which has the following bytes
[13, 0, 0, 0, -48, 123, 34, 97, 34, 58, 32, 34, 116, 101, 115, 116, 34, 125]
when this file is read in java i slip away
\\r\\x00\\x00\\x00\\xd0{"a": "test"}
when I do .getBytes() on this line, I get
[92, 114, 92, 120, 48, 48, 92, 120, 48, 48, 92, 120, 48, 48, 92, 120, 100, 48, 123, 34, 97, 34, 58, 32, 34, 116, 101, 115, 116, 34, 125]
I need to convert a string to valid bytes, I have no way to change the way the file is read, unfortunately. I know in Python that you open a file with the 'rb' mode and you are good to go. If java has this ability, I cannot use it.
So, how can I convert the string that Java reads to the original byte array that was written to the file?
Sorry if this question is stupid, but I'm so green when it comes to Java.
EDIT: So, I believe that my question is different from the proposed "duplicate question" link. It does not take every literal value in a java string and converts it back to byte. The reader reads a string in java. \x00 now \\x00 , which is not the same byte value. So it seems to me that I need a way to unescaping a string?
Hex Editor File
0000000: 5c72 5c78 3030 5c78 3030 5c78 3030 5c78 \r\x00\x00\x00\x 0000010: 6430 7b22 6122 3a20 2274 6573 7422 7d0a d0{"a": "test"}.
String that java is being viewed in hex editor
0000000: 5c5c 725c 5c78 3030 5c5c 7830 305c 5c78 \\r\\x00\\x00\\x 0000010: 3030 5c5c 7864 307b 2261 223a 2022 7465 00\\xd0{"a": "te 0000020: 7374 227d 0a st"}.