dede网站底部,服饰的网站建设,软件实施工程师工资一般多少,个人开通微信小程序转载自 Properties文件的XML格式
想必大家都用过*.properties文件#xff0c;作为配置文件。但是#xff0c;如果该文件写入了中文#xff0c;待编译后内容就会成为乱码#xff0c;使用native命令也好、使用ant执行编码转换也好#xff0c;多少有点麻烦#xff0c;与其如…转载自 Properties文件的XML格式
想必大家都用过*.properties文件作为配置文件。但是如果该文件写入了中文待编译后内容就会成为乱码使用native命令也好、使用ant执行编码转换也好多少有点麻烦与其如此我们不如直接使用properties的xml格式。
?xml version1.0 encodingUTF-8?
!DOCTYPE properties SYSTEM http://java.sun.com/dtd/properties.dtd
properties comment系统配置/comment entry keylogo.location![CDATA[/image/logo/]]/entry entry keymail.host![CDATA[webmasterzlex.org]]/entry entry keysite.name![CDATA[zlex中文网站]]/entry entry keywelcome![CDATA[欢迎您{0}]]/entry
/properties 对应原有的properties文件
#系统配置
logo.location/image/logo/
mail.hostwebmasterzlex.org
site.namezlex中文网站
welcome欢迎您{0}
这里需要替换{0}可以使用MessageFormat参考如下代码
private FileInputStream fis; Before public void init() { try { fis new FileInputStream(new File(config.xml)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } } Test public void t() { Properties properties new Properties(); try { properties.loadFromXML(fis); System.err.println(MessageFormat.format( (String) properties.get(welcome), snowolf)); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
得到控制台输出
欢迎您snowolf因为使用XML格式不受系统编译影响不存在中文问题