40

It seems to be really crazy, but I can't do anything with broken encoding in the console of my IntelliJ IDEA.

Things I made to overcome this:

  1. Set -Dfile.encoding=UTF-8 and -Dfile.encoding=UTF-8 in both idea.exe.vmoptions and idea64.exe.vmoptions (I use 64 bit version though).
  2. Added -Dfile.encoding=UTF-8 and -Dfile.encoding=UTF-8 to run/debug configuration of my application.
  3. Changed Settings > Editor > File encodings IDE Encoding/Project Encoding/Default encoding for property files to UTF-8.

Having all these done, there is still no luck and symbols are not shown correctly in the console. I tried to debug the java.io.PrintStream#println(java.lang.String) method and found out that System.out.textOut.out.se.cs equals to windows-1251. No idea where this value is coming from.

This issue has been bothering me for a long time and I was unable to find anything in the web that could help me.

J. Chomel
  • 8,193
  • 15
  • 41
  • 69
mr.nothing
  • 5,141
  • 10
  • 53
  • 77
  • Please provide some code: http://stackoverflow.com/help/mcve – Alastair McCormack Feb 05 '16 at 20:26
  • 1
    `System.out.println("\u0394");` prints [Greek Character Delta](http://unicode-table.com/en/0394/), Δ . What does that print for you? – Jake Hendy Feb 05 '16 at 20:56
  • 1
    @JakeHendy Sorry for delayed answer. The result of `System.out.println("\u0394");` is `?`. – mr.nothing Feb 08 '16 at 06:51
  • @AlastairMcCormack I'll try to provide a sample project, but not sure I'll be able to cause I have another project for testing purposes next to this one and encoding in it's console seems to be ok (unfortunately creating project from scratch is too complex and is not an option for me). – mr.nothing Feb 08 '16 at 06:53
  • @mr.nothing in File > Settings > Editor > Console, what's the typeface compared to the "working" project? – Jake Hendy Feb 08 '16 at 06:57
  • @JakeHendy, It seems that File > Settings > Editor > Console is absent in my version of Intellij Idea (14.1.4). What version do you refer to? – mr.nothing Feb 08 '16 at 07:02
  • @mr.nothing apologies. Wrong place. Settings > Editor > Colors & Fonts > Console Font. Is the result of `System.out...` the same in your other testing project? – Jake Hendy Feb 08 '16 at 09:29
  • @JakeHendy, thanks for responce, checked this, it seems to be identical. The primary one is Monospaced, the secondary one is not configured in both projects. – mr.nothing Feb 08 '16 at 09:32
  • @mr.nothing is there a reason that you don't update to the latest version (15.0.2)? Or at least to version 14.1.6 – simon Feb 08 '16 at 13:24
  • 1
    This is duplicate of http://stackoverflow.com/questions/29695918/intellij-idea-console-issue (this one has better title.. so duplicating may not be much use ... – Jayan Feb 15 '16 at 09:11
  • @Jayan, actully, no, it's not. See accepted answer. – mr.nothing Feb 15 '16 at 09:14
  • 1
    Official docs: https://www.jetbrains.com/help/idea/configuring-output-encoding.html. @CrazyCoder, it needs fixing of settings file paths for all OSes. – Vadzim Nov 28 '17 at 09:25
  • See also [Unicode characters appear as question marks in IntelliJ IDEA console](https://stackoverflow.com/questions/1082343/unicode-characters-appear-as-question-marks-in-intellij-idea-console) – Vadzim May 13 '20 at 15:04

11 Answers11

47

This works for me.

  1. Close your intellij idea
  2. Search and open file idea.exe.vmoptions inside idea installed, for example: "C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\bin". After add next line: -Dfile.encoding=UTF-8
  3. (Optional) if you have file idea64.exe.vmoptions, add the same line too.
  4. Start your intellij idea.
Nimantha
  • 6,405
  • 6
  • 28
  • 69
Marcos QP
  • 656
  • 6
  • 5
  • 24
    Thanks!! This is also accessible from `Help > Edit custom VM options...` then restart IntelliJ. I literally tried everything: changing encoding settings everywhere in IntelliJ, changing JVM options set by properties file, build.gradle file, IntelliJ, run configuration, environment variable, etc. Also tried changing system wide encoding nothing worked but this. – Nicolas Nov 16 '19 at 01:54
  • 2
    Two points: - I highly recommend the option of @Nicolas because the path from me was not under program files but `C:\Users\name\.IdeaIXXX\config\idea64.exe.vmoptions` - If it still does not work, verify that the encoding of your file is also in `UTF8`, @chenyi1976 put a good tutorial just below – gerardnico Feb 28 '20 at 12:05
20

try

-Dconsole.encoding=UTF-8

instead of

-Dfile.encoding=UTF-8
sunny
  • 1,887
  • 3
  • 29
  • 40
14

You may have modified the wrong file,

not : C:\Program Files\JetBrains\IntelliJ IDEA xxxx\bin\idea64.exe.vmoptions

should be: C:\Users\USER_NAME\.IntelliJIdeaxxxx\config\idea64.exe.vmoptions

you can add both -Dfile.encoding=UTF-8 and -Dconsole.encoding=UTF-8

xinyong Cheng
  • 1,786
  • 1
  • 10
  • 6
  • 2
    For version `2020.x`, I found a config file along this path: `C:\Users\USER_NAME\AppData\Roaming\JetBrains\IntelliJIdea2020.x\idea64.exe.vmoptions`. Added these two parameters, restarted and now the text is displayed is right. Thanks! – Vyaches Sep 13 '20 at 20:39
6

My theory is that your java class file are using "windows-1251" encoding, and you need to set it "UTF-8".

looks at the screenshots below. enter image description here enter image description here

To reset all files encoding, you can manually edit encodings.xml. enter image description here You can change the default file encoding in settings dialog. enter image description here

chenyi1976
  • 1,104
  • 9
  • 17
2

In Intelij coding java console

System.out.println("Hà nội");  // unicode content

Using SDK amazon corretto version ... can help you println unicode console

enter image description here

quangdang
  • 116
  • 7
2

The only thing that worked for me is set environment variable JAVA_TOOLS_OPTIONS Run in win cmd

setx JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8

And restart IDE.

Sergey Irisov
  • 468
  • 4
  • 7
2

The garbled characters have been resolved with the following settings. (IntelliJ IDEA Community 2022.2)

 - Build, Execution, Deployment > Build Tools > Runner > Environment vairables.
 - JAVA_TOOL_OPTIONS=-Dfile.encoding=UTF8

ScreenShot

Procrastinator
  • 2,526
  • 30
  • 27
  • 36
yukke
  • 21
  • 2
1

IntelliJ IDEA uses the operating system's shell internally as the console. In Windows that's Command Prompt. So if adding...

-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8

... to your VM Options under Help -> Edit Custom VM Options doesn't help, ensure your shell supports UTF-8 characters in the first place.

0

In my case, examining System.out.textOut.out.se.cs in debug hinted that IDEA picked up maven surefire arguments for every JUnit Run Configuration:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
        <!-- force 7-bit default encoding to ensure that nothing depends on it -->
        <argLine>-Dfile.encoding=ASCII</argLine>
    </configuration>
</plugin>

I've resolved this by adding -Didea.maven.surefire.disable.argLine=true to the idea64.exe.vmoptions file.

See also: https://www.jetbrains.com/help/idea/configuring-output-encoding.html.

Pang
  • 9,564
  • 146
  • 81
  • 122
Vadzim
  • 24,954
  • 11
  • 143
  • 151
0

If anyone has come across this problem and nothing works on the top answer, try to download another JDK version and use at SDK.

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
ogkasa
  • 1
0

As @ogkasa mentioned, if you have such a problem and nothing helps, just try to install another JDK version. Me personally tried every possible solution but none worked. So i just rolled back to JDK 17 and now cyrillic (which was my problem) works properly.