java中的properties文件中的中文需要用 \uxxxx来表示,非常麻烦。虽然有IDE的帮助,可以减少转码的过程。但这仍然是properties的一大缺陷。因此Light-commons加入了一个ExProperties类。可以支持iso-8859-1以外的编码格式。
#testutf8.properties
[quote]#测试
中文名=中文值
[/quote]
#TestExProperties.java
#testutf8.properties
[quote]#测试
中文名=中文值
[/quote]
#TestExProperties.java
ExProperties exProperties = new ExProperties();
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("testutf8.properties");
exProperties.load(is, "utf-8");
assertEquals("中文值", exProperties.getProperty("中文名"));
为解决Java中properties文件不支持UTF-8编码的问题,Light-commons引入了ExProperties类,该类允许properties文件使用除iso-8859-1外的编码格式,如UTF-8。通过示例演示如何加载包含中文名与中文值的properties文件。

被折叠的 条评论
为什么被折叠?



