Delete key and value from a property file?

harishtps picture harishtps · Nov 19, 2010 · Viewed 21.9k times · Source

I want to delete key and value which is stored in a property file. How can i do that????

Answer

BalusC picture BalusC · Nov 19, 2010

First load() it using the java.util.Properties API.

Properties properties = new Properties();
properties.load(reader);

Then you can use the remove() method.

properties.remove(key);

And finally store() it to the file.

properties.store(writer, null);

See also: