This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Have problems trying to with Properties store() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Have problems trying to with Properties store()" Watch "Have problems trying to with Properties store()" New topic
Author

Have problems trying to with Properties store()

James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
My web app does the following:

It takes some values from a .properties file, closes that inputstream and loads those properties into a Properties object (called 'props').

Then it modifies one of props's properties.

Up to this stage everything is fine. But then I do:

props.store(new java.io.FileOutputStream(propertiesFileLocation), null);

...but it has no effect. No exceptions are thrown, so I don't know why my .properties file hasn't changed.

Does anyone have any idea what it might be?

Thanks,
James
Horatio Westock
Ranch Hand

Joined: Feb 23, 2005
Posts: 221
Hi.

Just a stab in the dark, but the API says this:

"After the entries have been written, the output stream is flushed. The output stream remains open after this method returns."

You could try creating the stream non anonymously, then closing it manually.

Also, you could try writing something to the output stream manually, not using the Properties.store, just as a sanity check to see if the files etc are in the correct locations.
James Hodgkiss
Ranch Hand

Joined: Jan 22, 2004
Posts: 401
Horatio,

Thanks for the reply. I've just now found the answer though - I've recently upgraded to Netbeans 4.0 and it didn't dawn on me that it recreates the .properties file in the \build directory...

I've had a look in there and it's updated that .properties file fine, so all seems well!

Thanks for your help,
James
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Have problems trying to with Properties store()
 
Similar Threads
They faild me, and I don't know how to fight them back
manipulating xml files at runtime
using two properties files in struts
Error handling in Struts
Using hibernate.cfg.xml