包含中文的properties文件,第一行要空出来

项目的配置文件中包含了中文,文件的编码格式为UTF-8.

当读取properties文件时第一个Key总是失败,后面的Key则正常。

Properties类API(http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html)中提到如下一句话

The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding. Characters that cannot be directly represented in this encoding can be written using Unicode escapes as defined in section 3.3 of The Java™ Language Specification; only a single 'u' character is allowed in an escape sequence. The native2ascii tool can be used to convert property files to and from other character encodings.

大体意思是, properties文件是基于行来读取和存储键值对的, 而期望的输入/输出流字符编码是ISO 8859-1. 那些不能使用该方式存储的字符集呢, 需要使用native2ascii命令对property文件进行转码.

解决方案为:在properties文件的首先加为空行(或写注释也可以)

参考:http://blog.csdn.net/pansanday/article/details/49895399

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值