I want to use a key defined in properties file as a variable like this :
key1= value1
key2= value2
key3= key1
I try :
key3= {key1}
or
key3= ${key1}
But it dosn't work !
Any idea please ?
When you define the value of a key in properties file, it will be parsed as literal value. So when you define key3= ${key1} , key3 will have value of "${key1}".
Core Java bootcamp program with Hands on practice The Properties file can be used in Java to externalize the configuration and to store the key-value pairs. The Properties. load() method of Properties class is convenient to load . properties file in the form of key-value pairs.
Our key. properties file is in flutter_app/android/key. properties .
Java's built-in Properties class doesn't do what you're looking for.
But there are third-party libraries out there that do. Commons Configuration is one that I have used with some success. The PropertiesConfiguration
class does exactly what you're looking for.
So you might have a file named my.properties
that looks like this:
key1=value1
key2=Something and ${key1}
Code that uses this file might look like this:
CompositeConfiguration config = new CompositeConfiguration();
config.addConfiguration(new SystemConfiguration());
config.addConfiguration(new PropertiesConfiguration("my.properties"));
String myValue = config.getString("key2");
myValue
will be "Something and value1"
.
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