I am using one .properties
file. In that I have following config parameters :
Appnameweb = app1
Appnamemobile = app2
Appnameweb1 = app3
There can be many config param starting with Appname provided by user. How to read all properties file parameters in which key will contain particular String like in this case Appname?
Generally take a look on javadoc of java.util.Properties
. To make you life easier I will give you this code snippet that can help you to start:
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
}
}
Properties props = new Properties();
props.load(new FileInputStream("file.properties"));
Enumeration<String> e = props.getNames();
List<String> values = new ArrayList<String>();
while(e.hasMoreElements()) {
String param = (String) e.nextElement();
if(param != null && param.contains("Appname")) {
values.add(props.getProperty(param));
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With