Reputation: 1103
I am taking radio stream and trying to read its metadata. It contains some Danish character which are showing as ? marks, so I tried below conversion
String s = new String(streammetadatastring.getBytes(StandardCharsets.UTF_16), StandardCharsets.ISO_8859_1);
now it removed the ? marks but showing wrong characters. I tried other ways but not getting the right values.
Upvotes: 1
Views: 1256
Reputation: 206916
A line of code like what you posted:
String s = new String(streammetadatastring.getBytes(StandardCharsets.UTF_16),
StandardCharsets.ISO_8859_1);
does not do anything useful.
A character encoding is a mapping from characters to bytes and vice versa. What you are doing in that line of code is convert a string to bytes using the UTF-16 character encoding, and then you immediately convert the bytes back to a string using the ISO-8859-1 encoding. That will not produce anything useful - the bytes contain UTF-16 encoded characters, not ISO-8859-1 encoded characters.
To make the Danish characters display correctly, you must make sure that wherever you display it (the command prompt window? a Linux shell? an HTML page? a GUI?) uses a font that contains the characters, and that you specify the correct character encoding (how you do that, depends on where you display the characters).
Upvotes: 2