Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Persisting Properties File Problem

 
Daniel Simpson
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dieskun Koper
Ranch Hand
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 85
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again, Dieskun! I appreciate all of your helpful responses!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic