我正在使用一个.properties
文件。我有以下配置参数:
Appnameweb = app1
Appnamemobile = app2
Appnameweb1 = app3
可以有许多由用户提供的以 Appname 开头的配置参数。
如何读取所有属性文件参数,其中键将包含特定字符串(如本例中的 Appname)?
一般看一下javadocjava.util.Properties
。为了让您的生活更轻松,我将为您提供以下代码片段,可以帮助您开始:
Properties props = new Properties();
props.load(new FileInputStream("myfile.properties"));
for (Enumeration<?> e = props.propertyNames(); e.hasMoreElements(); ) {
String name = (String)e.nextElement();
String value = props.getProperty(name);
// now you have name and value
if (name.startsWith("Appname")) {
// this is the app name. Write yor code here
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)