What I’m trying to do is generate an array of chars that represent certain ASCII values in a certain ISO/IEC charset. Let’s say, if I’m intersted in ASCII values 211-217 of ISO/IEC 8859-7 charset then the result should be { Σ, Τ, Υ, Φ, Χ, Ψ, Ω }. I tried this:
for (int i = 211; i <= 217; i++) {
System.out.println(String.valueOf((char)i));
}
But the results are based on the default system charset.
You cannot convert individual character codes in particular encoding to
chars directly, therefore you need to usebyte[]toStringconversion instead. Since ISO-8859-7 is a single-byte encoding, each character code corresponds to onebyte:EDIT: Using the output format given above you can make sure that Unicode code points are decoded correctly, as specified by ISO-8859-7. If you still see
?s instead of characters, it’s a problem with output – your console doesn’t support these characters.Check a result of
System.getProperty("file.encoding")– it should be some kind of Unicode (UTF-8, etc). If you run your code from IDE check its configuration for console encoding settings.