File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to edit a properties file in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to edit a properties file in java" Watch "How to edit a properties file in java" New topic
Author

How to edit a properties file in java

Ananda Sen
Greenhorn

Joined: Dec 05, 2007
Posts: 8
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

Joined: Feb 23, 2009
Posts: 1183
Isn't setProperty what you want ?


JDBCSupport - An easy to use, light-weight JDBC framework -
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14435
    
  23

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ireneusz Kordal
Ranch Hand

Joined: Jun 21, 2008
Posts: 423
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

Joined: Dec 24, 2008
Posts: 28
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

Joined: Feb 24, 2006
Posts: 6662
    
    5

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 ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Mukesh Ranjan
Greenhorn

Joined: Jun 24, 2009
Posts: 22
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to edit a properties file in java