I have a problem when trying to convert bytes to String in Java, with code like:
byte[] bytes = {1, 2, -3};
byte[] transferred = new String(bytes, Charsets.
In Java, byte
is signed, where negative values are above 127. And those you used (-3 = 0xFD, -32 = 0xE0) are not valid in UTF-8, so they both are converted to Unicode codepoint U+FFFD REPLACEMENT CHARACTER
, which is converted back to UTF-8 as 0xEF = -17, 0xBF = -65, 0xBD = -67.
You cannot expect that random byte values are correctly interpreted as UTF-8 text.