Editing properties file from java class

I am using the MVC model for developing a web application. I am using a properties file for store some settings.I am trying to change the value of a key in the property file using the following code.

publicvoid setValue(String thekey, String thevalue)throws IOException{

Properties prop =new Properties();

FileOutputStream out =new FileOutputStream("browserpush.properties");

prop.setProperty(thekey,thevalue);

prop.store(out,null);

prop.list(System.out);

out.close();

}

The above code completely erases all the other values inbrowserpush.properties and creates a new one with only the specified parameters(thekey,thevalue).

clearly i just want to change the value of one of the keys in thebrowserpush.properties file with other values unchanged.

do i need to load the whole property file, remove the particular key and add the key again with new value before outputting it? or any other solution?

Thanks in advance

[1297 byte] By [m_kka] at [2007-11-26 19:12:33]
# 1
> do i need to load the whole property file, remove the> particular key and add the key again with new value> before outputting it?Yes. (Except you don't need to delete before adding, adding overwrites anything that may already be there.)
DrClapa at 2007-7-9 21:11:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

that worked perfectly. I got one more question . I am using eclipse IDE to develop the application. I have placed both the java class and the properties file in the same folder.

When i read it using prop.load(this.getClass().getResourceAsStream("browserpush.properties"));

it reads fine but when I am outputting it with the FileOutputStream out =new FileOutputStream("browserpush.properties");

The new file is created directly under eclipse directory and not under the same folder as the java class.

Any solution for this. I havent found an answer over the net yet.

Thank you.

m_kka at 2007-7-9 21:11:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...