In a java application, I am using .properties file to access application related config properties.
For eg.
AppConfig.properties the contents of which are say,
settings.user1.name=userone
settings.user2.name=usertwo
settings.user1.password=Passwrd1!
settings.user2.password=Passwrd2!
I am accesing these properties through a java file - AppConfiguration.java like
private final Properties properties = new Properties();
public AppConfiguration(){
properties.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("AppConfig.properties"));
}
Now, instead of keeping all the key-value properties in one file, I would like to divide them in few files(AppConfig1.properties, AppConfig2.properties, AppConfig3.properties etc.).
I would like to know if it is possible to load these multiple files simultaneously.
My question is not similar to - Multiple .properties files in a Java project
Thank You.
Yes. Simply have multiple load statements.
properties.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("AppConfig1.properties"));
properties.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("AppConfig2.properties"));
properties.load(Thread.currentThread().getContextClassLoader()
.getResourceAsStream("AppConfig2.properties"));
All the key-value pairs will be available to use using the properties object.
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