0

i want to read values from two properties files. i have below code. is there any good approach? from props i am getting values.here i have servletcontext available.

InputStream stream = event.getServletContext().getResourceAsStream("someOne.properties");
InputStream streams = event.getServletContext().getResourceAsStream("someTwo.properties");
Properties props = new Properties();
props.load(stream);
Properties props2 = new Properties();
props2.load(streams);

Thanks!

4

1 回答 1

4

If you want to merge the properties of the two files, simply use the same Properties instance :

Properties props = new Properties();
props.load(stream);
props.load(streams);

As can be verified in the source code of the Properties class, old properties with the same key will be replaced but the properties with different keys won't be erased (this point doesn't seem to be explicitly specified in javadoc).

Don't forget to close the streams afterwards :

stream.close();
streams.close();
于 2012-07-09T09:29:52.090 回答