47

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.

13

14 Answers 14

55
+50

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.
2
  • 29
    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, 2019 at 1: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, 2020 at 12:05
20

try

-Dconsole.encoding=UTF-8

instead of

-Dfile.encoding=UTF-8
0
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

1
  • 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!
    – Viaches
    Sep 13, 2020 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

1
  • Thank you for your input, but my problem was a little bit different.
    – mr.nothing
    Feb 15, 2016 at 9:38
2

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.

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

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.

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

1

If you use gradle you can just add

org.gradle.jvmargs=-Dfile.encoding=UTF-8

to your %userprofile%\\.gradle\gradle.properties file (or gradle.properties on project level).

Ref.: https://docs.gradle.org/current/userguide/common_caching_problems.html#system_file_encoding

1

This helps me:

By default, IntelliJ IDEA uses the system encoding to view console output.

  1. In the Settings dialog (Ctrl + Alt + S), select Editor | General | Console.
  2. Select the default encoding from the Default Encoding list.
  3. Click OK to apply the changes.
  4. Reopen your console.

From jetbrains.com

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.

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.

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.

0

Polish letters (Polskie litery) I got with @Vadzim's tips:

1. Edit POM.xml

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.22.2</version>
            <configuration>
                <argLine>-Dfile.encoding=UTF-8</argLine>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.apache.maven.surefire</groupId>
                    <artifactId>surefire-junit47</artifactId>
                    <version>2.22.2</version>
                </dependency>
            </dependencies>
</plugin>

2. Edit idea64.exe.vmoptions file by adding
-Didea.maven.surefire.disable.argLine=true

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Oct 18, 2023 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.