I\'m currently working on an application to validate and parse CSV-files. The CSV files have to be encoded in UTF-8, although sometimes we get files in a false encoding. The
Byte sequences that cannot be decoded correctly will be replaced with the "replacement character", \uFFFD
, which is displayed like this: �. However, if the output device doesn't support that character, it is likely to use a question mark (?) instead.
So, after decoding the UTF-8 data into String
objects, search for occurrences of \uFFFD
.
Alternatively, if you set up an InputStreamReader
with an instance of CharsetDecoder that you create yourself, you can get a lot more control. For example, you can specify that if any byte sequences that cannot be decoded, an Exception
should be raised. Or you can ignore them. Or you can specify a different character as the replacement character.