• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to edit a properties file in java

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't setProperty what you want ?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic