<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd"> <properties> <comment>系统配置</comment> <entry key="logo.location"><![CDATA[/image/logo/]]></entry> <entry key="mail.host"><![CDATA[webmaster@zlex.org]]></entry> <entry key="site.name"><![CDATA[zlex中文网站]]></entry> <entry key="welcome"><![CDATA[欢迎您,{0}!]]></entry> </properties>
对应原有的properties文件
#系统配置 logo.location=/image/logo/ mail.host=webmaster@zlex.org site.name=zlex中文网站 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格式,不受系统编译影响,不存在中文问题!版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。