属性文件properties的字符编码问题

#\u914d\u7f6e\u6839\u65e5\u5fd7\uff0c\u7528\u4e8e\u8bb0\u5f55\u5168\u5c40\u4fe1\u606f
#\u8bbe\u7f6e\u8f93\u51fa\u7ea7\u522b\u4e3ainfo\uff0c\u9664\u6b64\u4e4b\u5916\u8fd8\u6709OFF\u3001FATAL\u3001ERROR\u3001WARN\u3001INFO\u3001DEBUG\u3001ALL
#\u8bbe\u7f6e\u8f93\u51fa\u4f4d\u7f6e\u540d\u79f0\u4e3aconsole
log4j.rootLogger = info,console,filelog

重新安装了开发环境,打开properties文件看到注释居然全部变了样,后来发现原来这种文件的编码不支持中文,默认是拉丁字符集,这样的话中文注释就很不方便了,需要转换工具,想起以前用过的eclipse插件properties editor插件,安装后打开,棒棒哒。

#配置根日志,用于记录全局信息
#设置输出级别为info,除此之外还有OFF、FATAL、ERROR、WARN、INFO、DEBUG、ALL
#设置输出位置名称为console
log4j.rootLogger = info,console,filelog

这个编辑器可以直接编辑属性文件的Unicode转义字符转换成Unicode,比通使用native2ascii要节省时间和精力。除了编辑器的常规功能外,插件还集成了Eclipse。文件可以在IDE中打开并保存在unicode中。它可以通过直观和简单的操作来使用。 


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在处理.properties文件时,如果文件中的中文字符出现乱码,一般是由于编码不一致引起的。通过查阅资料,可以采取以下方法解决这个问题。 一种解决方法是在代码中指定编码来获取.properties文件中的属性值。可以使用类似下面的代码片段: ``` public static String getProperty(Properties properties, String key, String encoding) throws UnsupportedEncodingException { // 参数检查 if (properties == null) return null; // 获取属性值 String value = properties.getProperty(key); if (value == null) return null; // 编码转换,将ISO8859-1编码字符串转换为指定编码 value = new String(value.getBytes("ISO8859-1"), encoding); return value; } ``` 这样就可以解决.properties文件属性值中的中文乱码问题。 另一个可能引起乱码的原因是编码冲突。如果输出和读入的编码不一致,就有可能导致中文乱码问题。因此,在使用API操作.properties文件时,应该确保编码的一致性。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [properties中文乱码问题](https://blog.csdn.net/exterminator/article/details/8136432)[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: 100%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值