Loading multiple properties files

travega picture travega · Apr 16, 2012 · Viewed 29.4k times · Source

Is it possible to stack loaded properties in Java? For instance can I do:

Properties properties = new Properties();

properties.load(new FileInputStream("file1.properties"));
properties.load(new FileInputStream("file2.properties"));

and access properties from both?

Answer

Eugene Retunsky picture Eugene Retunsky · Apr 16, 2012

You can do this:

Properties properties = new Properties();

properties.load(new FileInputStream("file1.properties"));

Properties properties2 = new Properties();
properties2.load(new FileInputStream("file2.properties"));

properties.putAll(properties2);

NOTE : All the keys maintained are unique. So, the later properties loaded with same key will be overridden. Just to keep for your ref :)