Load the properties file using java.util.Properties
.
Code snippet –
Properties prop = new Properties();
InputStream in = getClass().getResourceAsStream("xyz.properties");
prop.load(in);
It provides Properties#setProperty(java.lang.String, java.lang.String)
which helps to add new property.
Code snippet –
prop.setProperty("newkey", "newvalue");
This new set you can save using Properties#store(java.io.OutputStream, java.lang.String)
Code Snippet –
prop.store(new FileOutputStream("xyz.properties"), null);