I want to print russian and german characters in windows console. So I wrote a small test program to understand how well it works:
PrintStream ps = new PrintStream(System.out, false, "UTF-8");
ps.println("öäüß гджщ");
Then I started cmd.exe, changed its font to Lucida Console, which supports Unicode, changed code page to Unicode with "chcp 65001" and executed my program.
The german and russian characters were printed but there was a little more text than I expected (underlined with red):
But the text is printed correctly in the Eclipse console. Is there a way to print it correctly in windows console? I use Windows 7.
I've just solved the problem with JNI, but it is still interesting whether it is doable with pure java.
Inserting Unicode characters To insert a Unicode character, type the character code, press ALT, and then press X. For example, to type a dollar symbol ($), type 0024, press ALT, and then press X.
Get the new Windows Terminal. It has full support for Unicode and UTF-8.
Unicode characters are distinguished by code points, which are conventionally represented by "U+" followed by four, five or six hexadecimal digits, for example U+00AE or U+1D310.
Every time you open or write a file, a certain encoding will be applied. But sometimes we forget that also our IDE (Eclipse in your case) has an encoding.
When you are typing a certain text between quotes, it is displayed and typed in a certain encoding, the encoding of your IDE. Your assumption is that the encoding of your output stream (UTF-8) will also guarantee that the text is displayed with that specific encoding. However, I think also here again the encoding of your IDE is applied.
I would propose to double check your encoding of eclipse. Perhaps this can solve your problem. Certainly worth a try, isn't it ? :)
For a global encoding setting add the following code to the eclipse.ini file
-Dfile.encoding=UTF-8
EDIT:
I would just like to add the following. I performed the following steps as an experiment.
This does not confirm much, but it does confirm the fact that DOS can do the job if the content is foreseen in the right encoding.
EDIT2:
@ka3ak It's been over 2 years, but while reading a book about Java I/O I stumbled upon the following.
System.console().printf(...)
has better support for special characters than theSystem.out.println(...)
method.
Since the PrintStream
just wraps around the System.out
stream, I guess you have the same limitations. I am wondering if this could have solved the problem. If it still matters, please give it a try. :)
Other posts on stackoverflow report similar things: console.writeline and System.out.println
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With