Loading multiple properties files

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

    Yes, you need to pass the default properties file in the constructor. Like this you can chain them up.

    E.g.:

    Properties properties1 = new Properties();
    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream("file1.properties"))){
        properties1.load(bis);
    }
    
    Properties properties2 = new Properties(properties1);
    try (BufferedInputStream bis = new BufferedInputStream(new FileInputStream("file2.properties"))){
        properties2.load(bis);
    }
    

提交回复
热议问题