[英]IntelliJ IDEA incorrect encoding in console output
這似乎真的很瘋狂,但我無法在我的 IntelliJ IDEA 控制台中對損壞的編碼做任何事情。
我為克服這個問題所做的事情:
idea.exe.vmoptions
和idea64.exe.vmoptions
中設置-Dfile.encoding=UTF-8
和-Dfile.encoding=UTF-8
(不過我使用的是 64 位版本)。-Dfile.encoding=UTF-8
和-Dfile.encoding=UTF-8
來運行/調試我的應用程序的配置。 完成所有這些后,仍然沒有運氣,並且控制台中的符號未正確顯示。 我嘗試調試java.io.PrintStream#println(java.lang.String)
方法,發現System.out.textOut.out.se.cs
等於 windows-1251。 不知道這個值是從哪里來的。
這個問題困擾了我很長時間,我在 web 中找不到任何可以幫助我的東西。
這對我有用。
嘗試
-Dconsole.encoding=UTF-8
代替
-Dfile.encoding=UTF-8
你可能修改了錯誤的文件,
不是: C:\\Program Files\\JetBrains\\IntelliJ IDEA xxxx\\bin\\idea64.exe.vmoptions
應該是: C:\\Users\\USER_NAME\\.IntelliJIdeaxxxx\\config\\idea64.exe.vmoptions
您可以同時添加-Dfile.encoding=UTF-8
和-Dconsole.encoding=UTF-8
唯一對我有用的是設置環境變量 JAVA_TOOLS_OPTIONS 在 win cmd 中運行
setx JAVA_TOOL_OPTIONS -Dfile.encoding=UTF8
並重啟 IDE。
就我而言,在調試中檢查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>
我已經通過將-Didea.maven.surefire.disable.argLine=true
添加到idea64.exe.vmoptions文件解決了這個問題。
另請參閱: https : //www.jetbrains.com/help/idea/configuring-output-encoding.html 。
IntelliJ IDEA 在內部使用操作系統的 shell 作為控制台。 在 Windows 中,這是命令提示符。 所以如果添加...
-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8
... Help -> Edit Custom VM Options
無濟於事,請確保您的外殼首先支持 UTF-8 字符。
如果有人遇到過這個問題並且在最佳答案中沒有任何效果,請嘗試下載另一個 JDK 版本並在 SDK 使用。
正如@ogkasa 所提到的,如果您遇到這樣的問題並且沒有任何幫助,請嘗試安裝另一個 JDK 版本。 我個人嘗試了所有可能的解決方案,但都沒有奏效。 所以我剛剛回滾到 JDK 17,現在西里爾字母(這是我的問題)可以正常工作。
亂碼已通過以下設置解決。 (IntelliJ IDEA 社區 2022.2)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.