How to write values in a properties file through java code

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);

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)