Intellij IDEA中.properties文件中文乱码问题的解决方法

Intellij IDEA中.properties文件中文乱码问题的解决方法

问题描述

当你读取application.properties配置文件时,发现中文乱码问题,如图
在这里插入图片描述

此时发现properties文件下方的编码格式并不是utf-8,页面停留在properties页面出,查看右下角,如图

在这里插入图片描述

解决方法

检查idea的默认设置,file->setting->editor->file encodings,发现默认编码并非utf-8,如下图。
在这里插入图片描述

把这个默认的设置为utf-8。就可以了。
在这里插入图片描述

在这里插入图片描述

有时打开.properties文件时,中文显示为utf8编码格式,可以在file->setting->editor->file encodings下把transparent native-to-ascll conversion勾选上

在Spring Boot项目,如果application.properties文件文出现乱码,这可能是因为Spring Boot默认使用的编码方式是ISO_8859_1。这意味着无论我们将application.properties文件保存为何种编码方式,最终它都会以ISO_8859_1的编码方式加载。 当我们的配置文件包含文字符时,如果不使用正确的编码方式进行设置,就会导致文字符在加载时出现乱码。为了解决这个问题,我们可以使用UTF-8编码方式来保存和加载application.properties文件。可以在项目的启动类上添加如下注解来指定编码方式: ```java @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } @PostConstruct public void init() { // 设置Spring Boot的编码方式为UTF-8 Charset charset = Charset.forName("UTF-8"); Charset.setDefaultCharset(charset); } } ``` 通过这种方式,我们可以确保application.properties文件文字符能够正确加载,避免出现乱码问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [如何处理从application.properties配置文件获取的汉字乱码问题](https://blog.csdn.net/u013232219/article/details/122270606)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [application.properties中文乱码解决方案](https://blog.csdn.net/qq_43753724/article/details/122351883)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

略安静一姑娘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值