This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to edit a properties file in java

 
Ananda Sen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am able to read and write a property file in java but unable to edit the value of an existing key.........Please help
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't setProperty what you want ?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does it mean exactly that you're "unable to edit the value of an existing key"?

Does it mean you don't know how to do it? Or does it mean you tried something, and it didn't work? And if it didn't work, then did you get a compiler error or a runtime error, or did the program behave differently from what you expected? Please explain in more detail.
 
Ireneusz Kordal
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Load the property file into any text editor (could be notepad on windows) and edit it.
The simplest form of every key-value pair is:
key=vaule
Here you have details about a format of property file:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html#load(java.io.InputStream)
 
Dmitry Mamonov
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may try to use http://commons.apache.org/configuration/
It's properties functionality allow to change properties values preserving properties file structure, including comments.
http://commons.apache.org/configuration/userguide/howto_properties.html#Properties_files
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ananda Sen wrote:I am able to read and write a property file in java but unable to edit the value of an existing key.........Please help


This question can have many answers based on what you want to do. If you can indeed read and write, what prevents you from editing existing values ?
 
Mukesh Ranjan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to read property file and then have to do setproperties and then have to use either save or store method for persistent storage

1. Load Properties first
2. props.setProperty(propertyName, NewValue);
3. props.save(new FileOutputStream(new File(propertyFilePath)), "");

May this will help you
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic