Loading multiple properties files

后端 未结 6 1819
自闭症患者
自闭症患者 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:14

    This should also work. If same property is defined in file1.properties and file2.properties, property in file2.properties will be in effect.

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

    Now the properties map will have properties from both files. If same key appears in file1 and file2, the value of the key from file1 will be updated in properties with value in file2 since I'm calling file1 then file2.

提交回复
热议问题