Search code examples
javaproperties-file

Loading multiple properties files


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?


Solution

  • 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 :)