jQuery in Action, 2nd edition*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Persisting Properties File Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Persisting Properties File Problem" Watch "Persisting Properties File Problem" New topic
Author

Persisting Properties File Problem

Daniel Simpson
Ranch Hand

Joined: Sep 02, 2004
Posts: 181
I have searched all throughout the forums for the answer to this question but I was unable to find it. I do all my configuring through a properties file, however, here is what happens:

1) Configure and persist settings for local mode
2) Configure and persist settings for network client mode.
3) Launch local mode and my settings were completely overwritten by the network client.

I've tried everything to get it to work, but am I doing something wrong?




I can't figure out how to store the settings and just update the ones I need to instead of it completely overwriting my file.
[ January 03, 2005: Message edited by: Daniel Simpson ]

SCJP 1.4<br />SCJD 1.4
Dieskun Koper
Ranch Hand

Joined: Aug 15, 2004
Posts: 85
Hi Daniel,

I believe I used the same Properties API as you are using. I don't understand your problem with it. The file is overwritten, but all the values that used to be in there should still be in there, unless you overwrite them with new values. Comments (the header) in the old property file will not be retained.

Regards,
Dies
Daniel Simpson
Ranch Hand

Joined: Sep 02, 2004
Posts: 181
Originally posted by Dieskun Koper:
Hi Daniel,

I believe I used the same Properties API as you are using. I don't understand your problem with it. The file is overwritten, but all the values that used to be in there should still be in there, unless you overwrite them with new values. Comments (the header) in the old property file will not be retained.

Regards,
Dies

Yeah, I'm not really sure why it won't keep the values. I insert the same header name for each different configuration. Here is what happens:
1)Launch Local mode: configure db file location
localFile = C:\\........
-exit program
2)Launch network client: Configure network client:
ipAddress = 107.......
port = 12345
-exit program
3)Open properties file manually with notepad and instead of having all 3 values saved from both modes, it only has ipAddress and port, but no localFile value.

I can't figure out why this is doing that.
[ January 04, 2005: Message edited by: Daniel Simpson ]
Dieskun Koper
Ranch Hand

Joined: Aug 15, 2004
Posts: 85
Sorry Daniel, I should have looked better at your code the first time.
At the start of your persist methods, you have 'FileOutputStream fout = new FileOutputStream(file);'. Note that this creates (overwrites) the existing property file. Then you load this file's properties. You just created the file, so the old properties are gone.

Regards,
Dies
Daniel Simpson
Ranch Hand

Joined: Sep 02, 2004
Posts: 181
Thanks again, Dieskun! I appreciate all of your helpful responses!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Persisting Properties File Problem
 
Similar Threads
writing to file
Adding to property files...
java.io.FileNotFoundException: FileOutputStream error?
How to create a properties file?
NX: RemoteDBAccess