ihavprobs
ihavprobs

Reputation: 1492

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?

Upvotes: 1

Views: 1057

Answers (2)

barti_ddu
barti_ddu

Reputation: 10299

You can store format string as a property, e.g.:

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

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

Upvotes: 3

Harry Joy
Harry Joy

Reputation: 59660

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");

Upvotes: 3

Related Questions