Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting values in properties file

 
r kh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to update a value in property file through the following code

Output: updated

But the values doesn't seem to get updated. In Fact, I am not getting any error even if the property or the file itself is not present.
 
T Mishra
Ranch Hand
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think, the stream must be closed before setting/updating value. Try this
 
Alexander Bondarev
Greenhorn
Posts: 12
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You actually deal with two files with the same name. One is located in the CLASSPATH. The class loader reads it in the method getResourceAsStream("myfile.properties"). The second file is created in the current working directory by the constructor FileOutputStream("myfile.properties"). The first file isn't updated because the value is changed in the second file.
 
r kh
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup, That's what happening! It works fine if I use OutputStream and InputStream everywhere.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic