Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / December 2006

Tip: Looking for answers? Try searching our database.

Writing to property file

Thread view: 
vincente13@gmail.com - 15 Dec 2006 10:46 GMT
Hi there,

I notice that when we try to write a value back to the property file,
the original comment in the property file will be removed.
Any idea how to keep the comment in the property file and yet updating
the key with the new value?

       String filename = "property.properties";
       Properties p = new Properties();
       p.setProperty("CacSrv", "SomeValue");
       p.store(new FileOutputStream(filename), null);
Robert Klemme - 15 Dec 2006 10:48 GMT
> Hi there,
>
> I notice that when we try to write a value back to the property file,
> the original comment in the property file will be removed.
> Any idea how to keep the comment in the property file and yet updating
> the key with the new value?

I believe you will have to parse the file yourself to extract the
comment.  Alternatively you could use an unused key for the comment.

>         String filename = "property.properties";
>         Properties p = new Properties();
>         p.setProperty("CacSrv", "SomeValue");
>         p.store(new FileOutputStream(filename), null);

You do not close the FileOutputStream properly.  This costs resources
and also might cause inconsistent file content.

    robert
Flo 'Irian' Schaetz - 15 Dec 2006 17:19 GMT
And thus, vincente13@gmail.com spoke...

>         p.store(new FileOutputStream(filename), null);

You are setting your header to null. So the properties don't have a
header... If you want text there, put it there instead of null.

Flo


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.