Loading multiple properties files

后端 未结 6 1749
自闭症患者
自闭症患者 2021-02-12 11:25

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

Properties properties = new Properties();

properties.load(new FileInputStream(\"file1.         


        
6条回答
  •  一整个雨季
    2021-02-12 12:18

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

提交回复
热议问题