idea中idea读取配置文件乱码properties文件中的中文乱码怎么解决?

&&&&&&&&&&&&&&&&&&
posts - 187,comments - 94,trackbacks - 0
问题:我的IDEA已经将文件的字符集设置成了UTF-8,但是中文在*.properties文件中还是会出现乱码,后来经同事指点修改了一项配置就ok了!话不多说,看下面的对比就清楚了。
注意:设置前IDEA编辑的时候中文是能正常显示的,重启IDEA之后就出现了乱码的现象,设置后再次重启IDEA乱码就自动ok了!
阅读(...) 评论()2被浏览592分享邀请回答0添加评论分享收藏感谢收起写回答博客分类:
解决办法有两种:
一、对属性配置文件进行转码处理
jdk安装完成后,会自带有native2ascii工具,可将属性配置文件中的中文字符转换成Unicode转义符,如汉字“中国”转换结果为“\u4e2d\u56fd”,这样读取时,就能正常显示中文了。
二、读取后,通过程序进行转码
Properties在load加载属性文件时,使用的是ISO-8859-1编码,我们可以在将属性内容读取后,再次进行一次编码即可(如utf-8,gbk)。
private static Properties prop = new Properties();
prop.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("conf.properties"));
//转码处理
Set&Object& keyset = prop.keySet();
Iterator&Object& iter = keyset.iterator();
while (iter.hasNext()) {
String key = (String) iter.next();
String newValue =
//属性配置文件自身的编码
String propertiesFileEncode = "utf-8";
newValue = new String(prop.getProperty(key).getBytes("ISO-8859-1"),propertiesFileEncode);
} catch (UnsupportedEncodingException e) {
newValue = prop.getProperty(key);
prop.setProperty(key, newValue);
} catch (Exception e) {
log.error("读取配置文件conf.properties出错!", e);
http://huangqiqing123.iteye.com/blog/1833854
浏览 10158
huangqiqing123
浏览: 1126855 次
来自: 济南
博主这个中文版的在哪找到的?
curl请求后没有响应是什么问题呢,QQ
你好,我想我想问一下,你的二维码生成字节数组怎么做到的 Zxi ...
xiaolei1004 写道int ind = doc.add ...
int ind = doc.addPicture(byteIn ...
(window.slotbydup=window.slotbydup || []).push({
id: '4773203',
container: s,
size: '200,200',
display: 'inlay-fix'idea使用gradle无法读取properties文件内容
我在实际使用的时候,经常出现gradle和idea的版本兼容问题。
系统配置经常不能够正确读入,,,
有什么方法能解决吗
写下你的评论...
Copyright (C) 2018 imooc.com All Rights Reserved | 京ICP备 号-11

我要回帖

更多关于 idea读取配置文件乱码 的文章

 

随机推荐