unicode characters appear as question marks in IntelliJ IDEA console
Is the file encoding configured correctly? See that "Settings | File Encodings" uses UTF-8. Printing ♠ works for me when I have IDE encoding and all files set to UTF-8. Recompiling may be needed after changing the encoding.
System.out uses the default encoding of the underlying operating system which typically is ISO-8859-1 or UTF-8. The first is what I have with the 1252 codepage under XP.
Is this in a CMD.EXE window, or inside an IDE?
A little update for the year 2015
TL;DR answer:
Go to Settings
-> Editor
-> File Encodings
-> Project Encoding
and set it to "UTF-8".
Expanded answer:
The reason why it does not work can be found by placing a breakpoint on a System.out.print()
call. When the breakpoint hits, you can add System.out
to Watches
, and you can see that System.out.textOut.out.se.cs
is set to windows-1252
or something similarly unsuitable.
The setting which magically worked for me (I do not know why) is in Settings
-> Editor
-> File Encodings
-> Project Encoding
. You need to set that to "UTF-8".
Then, unicode characters display properly on the console, and one more quick look with the debugger shows that the value of System.out.textOut.out.se.cs
has magically turned into UTF-8
.
I am saying "magically" because I do not see how and why an editor setting should affect the character set that System.out
gets instantiated with when launching/debugging an application. If someone knows what is the logic behind this, please do tell!
Go to Help > Edit Custom VM options... then add the following option:
-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8
I'm not sure if both are necessary but it worked for me. You need to restart IntelliJ for changes to be applied.
I had already tried changing every encoding setting in Intellij, setting those options in Gradle and changing the system encoding, this is the only one that worked.