mr.nothing
mr.nothing

Reputation: 5399

IntelliJ IDEA incorrect encoding in console output

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.

Upvotes: 50

Views: 67681

Answers (14)

Andrey Slyadz
Andrey Slyadz

Reputation: 41

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

Upvotes: 2

m02ph3u5
m02ph3u5

Reputation: 3161

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

Upvotes: 1

Tomasz Zdun
Tomasz Zdun

Reputation: 1

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

Upvotes: 0

yukke
yukke

Reputation: 21

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

Upvotes: 2

Sergey Irisov
Sergey Irisov

Reputation: 508

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.

Upvotes: 4

Andrew Ihnatiuk
Andrew Ihnatiuk

Reputation: 1

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.

Upvotes: 0

quangdang
quangdang

Reputation: 364

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

Upvotes: 1

ogkasa
ogkasa

Reputation: 1

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

Upvotes: 0

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.

Upvotes: 2

Marcos QP
Marcos QP

Reputation: 772

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.

Upvotes: 58

Vadzim
Vadzim

Reputation: 26160

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.

Upvotes: 0

xinyong Cheng
xinyong Cheng

Reputation: 1944

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

Upvotes: 13

chenyi1976
chenyi1976

Reputation: 1122

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

Upvotes: 5

sunny
sunny

Reputation: 1945

try

-Dconsole.encoding=UTF-8

instead of

-Dfile.encoding=UTF-8

Upvotes: 21

Related Questions