This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes JDK's Bug?! java.util.Properties don't save comments!    Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JDK Watch "JDK New topic

JDK's Bug?! java.util.Properties don't save comments!

Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Hi friends:
I want to edit a file using class java.util.Properties. My file is:

After I run my application,all the comment is lost!
My code is:

After I run my code,the change to this:

Where is my comments!? They are deleted by java.util.Properties!
All my comments information lost! why Properties class don't save comment? ;-(

When I face C# and Java I choose Java.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14991

The specifications of the Properties class and the load(...) and store(...) methods do not say anything about preserving your comments in the file.

This is not a JDK bug - the Properties class was just not designed to save files with comments etc. in exactly the same format as what you typed in by hand.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

I agree with Jesper.

[My Blog]
All roads lead to JavaRanch
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42958
If you absolutely need to preserve comments when programmatically modifying properties files, have a look at the UberProperties class.
I agree. Here's the link:
subject: JDK's Bug?! java.util.Properties don't save comments!
It's not a secret anymore!