The character 'ä' is (char)0xE4 ('\u00E4'), and 'õ' is (char)0xF5 ('\u00F5') in the Unicode. To see if the problem is of command line display or something other, first try file outputs or awt outputs. The command line dispay is concerned with the system setting not with Java codes.
Your string has 16-bit characters. When you write to System.out, at some point it will be converted to 8-bit byte values. What conversion is being done. Check this by using "String.getBytes()" and check the individual byte values that come back.
The second part of the equation is where you are displaying these bytes (the command prompt) and what character set it is using to interpret the bytes.
Because you see something different, it is a fact that the character set that Java is converting the characters to is not the character set that you command window (or whatever) is using.
Thanks for your response. Yes, the output is being wriiten exactly into the file. But when I print it thru Dos command window, it does not dislplay "as is". If so, how can I set my window properties.
No... Even though I set CHCP850, it does not print German chars as is. Can anybody help me, how can I ensure that I can print the exact German chars on my DOS window.
You may use an OutputStreamWriter and tell it to use a proper CodePage, like this (I decorate it with a PrintWriter in addition, so I can use the print() and println() methods):
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out, codePage));
Writing text with umlauts, accents, and the like through pw should give the desired result.
It works fine on Win XP!
But I am having a problem puzzling me myself, related to the same topic!
Namely, I can't seem to do same on Win 98, running a JRE without the "charsets.jar" which appears to be a requirement:
Although when checking the codepage active in my console, I get told that "850" is the "active codepage", when creating the OutputStreamWriter in the way demonstrated above, I get an UnsupportedEncodingException thrown.
Would anybody know why that should be the case?
And: I included the two required classes
sun.io.ByteToCharCp850.class and
sun.io.CharToByteCp850.class
in a small .jar-File and put this in my classpath, but this seems to be ignored.
Any help would be greatly appreciated! I found several forum entries on this topic, but they all seem to end in the wild...