I've spent almost 3 days to find out why in a big project the output of
System.out.println( "你好" );
is shown as "??" and in another project built-from-scratch it is shown as "你好".
I am using IntellijIdea, BUT the same thing happens to me while running it from a jar-file using
java -jar ...
The only two differences between those 2 project is in build system: first one uses gradle and second one uses none (just a simple project). The second difference is about output of the following code
System.out.println("Charset.defaultCharset=" +
Charset.defaultCharset());
The first one types "Charset.defaultCharset=windows-1252", second one "Charset.defaultCharset=UTF-8"
Well, I HAVE read about:
the encoding in IntellijIdea, all settings between 2 projects are the same (Settings → File Encoding → Project Encoding → IDE Encoding)
About the encoding of file setting in the right lower corner in Idea
in cmd console did
set JAVA_TOOL_OPTIONS=-Dconsole.encoding=UTF8
set JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8
Played with gradle properties in gradle.build
org.gradle.jvmargs='-Dfile.encoding=UTF-8'
systemProp.file.encoding=UTF-8
changed the the coding in command prompt via
chcp 65001
Those efforts bring me to nothing. Any ideas ?
BTW THERE IS almost the same question but with no answer. I cannot write there cause of low reputation Intellij Idea incorrect encoding in console output
the picture with settings in project that don't correctly display the output
Well, finally i've got it!
Navigate to Help -> Edit Custom VM Options...
Add those ones:
-Dfile.encoding=UTF-8
-Dconsole.encoding=UTF-8
Restart idea completely.