解决IntelliJ IDEA中文乱码的核心方法是统一设置文件编码为UTF-8,并修改虚拟机选项和编译器参数。

统一编码设置
全局文件编码:通过菜单栏 File -> Settings -> Editor -> File Encodings,将 Global Encoding、Project Encoding 和 Default encoding for properties files 均设为 UTF-8。



字体支持:在 Appearance 设置中选择支持中文的字体(如 Microsoft YaHei UI)。
虚拟机与编译器配置
修改VM选项
在IDEA安装目录的 bin 文件夹下,编辑 idea64.exe.vmoptions(64位系统)或 idea.exe.vmoptions(32位系统),末尾添加 -Dfile.encoding=UTF-8。

或通过菜单 Help -> Edit Custom VM Options 直接修改。

本文使用的是绿色版,所以直接在bin目录内修改idea64.exe.vmoptions文件内容。
编译器参数
对于Gradle项目,在 build.gradle 中添加 tasks.withType(JavaCompile) { options.encoding = 'UTF-8' }。
对于Maven项目,在 Run/Debug Configurations 的 VM options 中添加 -Dfile.encoding=UTF-8。
控制台乱码专项处理
Spring Boot项目:在 application.properties 中配置编码参数(如 spring.http.encoding.charset=UTF-8),并在Controller中设置 produces="text/plain;charset=UTF-8"。
Tomcat部署:在 Edit Configurations 的 VM options 中添加 -Dfile.encoding=UTF-8,并检查 logging.properties 文件编码。
如果您喜欢此文章,请收藏、点赞、评论,谢谢,祝您快乐每一天。