java 控制台输出中的 Intellij Idea 编码不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35231291/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 23:52:32  来源:igfitidea点击:

Intellij Idea incorrect encoding in console output

javaintellij-ideaencodingutf-8character-encoding

提问by mr.nothing

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

这似乎真的很疯狂,但我无法在我的 Intellij 想法的控制台中对损坏的编码做任何事情。

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.
  1. 在idea.exe.vmoptions 和idea64.exe.vmoptions 中设置-Dfile.encoding=UTF-8 和-Dfile.encoding=UTF-8(不过我使用的是64 位版本)。
  2. 添加 -Dfile.encoding=UTF-8 和 -Dfile.encoding=UTF-8 来运行/调试我的应用程序的配置。
  3. 将属性文件的设置 > 编辑器 > 文件编码 IDE 编码/项目编码/默认编码更改为 UTF-8。

Having all this done there is still no luck and symbols are not shown correctly in the console. I tried to debug 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.

完成所有这些后,仍然没有运气,并且符号未在控制台中正确显示。我试图调试 java.io.PrintStream#println(java.lang.String) 方法,发现 System.out.textOut.out.se.cs 等于 windows-1251。不知道这个值是从哪里来的。

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

这个问题一直困扰着我很长一段时间,我无法在网上找到任何可以帮助我的东西。

Thanks in advance for help.

预先感谢您的帮助。

回答by Marcos QP

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.
  1. 关闭你的智能想法
  2. 在安装的idea中搜索并打开idea.exe.vmoptions文件,例如:“C:\Program Files\JetBrains\IntelliJ IDEA 2018.3.2\bin”。添加下一行后:-Dfile.encoding=UTF-8
  3. (可选)如果您有文件idea64.exe.vmoptions,也添加相同的行。
  4. 开始您的 Intellij 想法。

I hope it helps you.

我希望它能帮助你。

Sorry for my english. I'm still learning. (Thanks @MrPromethee for suggestions)

对不起我的英语不好。我还在学习。(感谢@MrPromethee 的建议)

回答by sunny

try

尝试

-Dconsole.encoding=UTF-8

instead of

代替

-Dfile.encoding=UTF-8

回答by xinyong Cheng

You may have modified the wrong file,

你可能修改了错误的文件,

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

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

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

应该: C:\Users\USER_NAME\.IntelliJIdeaxxxx\config\idea64.exe.vmoptions

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

你可以同时添加-Dfile.encoding=UTF-8-Dconsole.encoding=UTF-8

回答by chenyi1976

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

我的理论是你的java类文件使用“windows-1251”编码,你需要将它设置为“UTF-8”。

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

看看下面的截图。 在此处输入图片说明在此处输入图片说明

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

要重置所有文件编码,您可以手动编辑 encodings.xml。 在此处输入图片说明您可以在设置对话框中更改默认文件编码。 在此处输入图片说明

回答by Vadzim

In my case examining System.out.textOut.out.se.csin debug hinted that IDEA picked up maven surefire argumentsfor every JUnit Run Configuration:

在我的情况下,System.out.textOut.out.se.cs在调试中检查暗示 IDEA为每个 JUnit 运行配置选择了 maven surefire 参数

<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=trueto idea64.exe.vmoptionsfile.

我已经通过添加-Didea.maven.surefire.disable.argLine=trueidea64.exe.vmoptions文件解决了这个问题。

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

另请参阅https://www.jetbrains.com/help/idea/configuring-output-encoding.html