• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yashnoo lyo
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends:
I want to edit a test.properties 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 test.properties 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? ;-(
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15354
39
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Jesper.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you absolutely need to preserve comments when programmatically modifying properties files, have a look at the UberProperties class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic