Loading multiple properties files

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

    Yes the properties stack. Properties extends Hashtable and load() simply calls put() on each key-value pair.

    Relevant code from the Source:

    String key = loadConvert(lr.lineBuf, 0, keyLen, convtBuf); 
    String value = loadConvert(lr.lineBuf, valueStart, limit - valueStart, convtBuf); 
    put(key, value); 
    

    In other words, loading from a file doesn't clear the current entries. However, note that if the two files contain entries with the same key, the first one will be overwritten.

提交回复
热议问题