简体   繁体   中英

Java configuring in properties file

I want to configure a property in my properties file. But that will not be a static value. For example,

var=abc some_unknown_string_here def

I will set the value for the unknown string within the java program. Is it possible to have a configuration like this?

As a hack you can do like this:

In properties file:

var = abc%_%xyz

In java file

//--- code to load property file
String propVar = properties.getProperty("var");
String myVar = propVar.replace("%_%","the_string_want_to_set_here");

You can store format string as a property, eg:

Properties properties = new Properties();
properties.put("foo", "hi, %s");

String s = properties.getProperty("foo");
System.out.println(String.format(s, "bar"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM