Solved

retaining comment in properties file

Posted on 2002-04-17
7
277 Views
Last Modified: 2008-02-26
I'm loading properties file using properties api and saving it back with changes using same api...but if any comments were present in the file (preceded by #)..are getting lost if i save back.

Is their any way to retain the comments which were present in the file while saving back.

Thanks,
0
Comment
Question by:vibhav
7 Comments
 
LVL 9

Expert Comment

by:Venci75
ID: 6947531
.
0
 
LVL 3

Accepted Solution

by:
saxaboo earned 50 total points
ID: 6947539
AFAIK, there is no way to retain the header or comments. As a workaround, you can use a dummy property :

---- myfile.properties ----
#This is a comment
myvalue1=foo
myvalue2=bar
__MY_COMMENT__=This is a comment \
               that spans on 3 \
               lines

HTH,

-S
0
 
LVL 3

Expert Comment

by:shyamkumarreddy
ID: 6947540
Which mode do u open the file.
I think u have used write mode to do it.
So u r loosing your comments.
Did u try to write it back to the file with comments.

Shyam
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 2

Expert Comment

by:Andrey_Kulik
ID: 6947547
Default implementation of java.util.Properties ignores all comments. You could create wrapper that will replace all first '#' or '!' chars in property file with unique strings like:
#comment
comment206467=comment

before reading property file and will replace all this properties names with '#' or '!' symbols back when property file will be stored.

Best regards
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6956322
Please click the link below to manage all your open and locked questions here needing your response and attention.
http://www.experts-exchange.com/jsp/memberProfile.jsp?mbr=vibhav&showQHistory=true
Moondancer - EE Moderator
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7972300
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Answered by: saxaboo
Please leave any comments here within the next seven days.
 
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
 
Venci75
EE Cleanup Volunteer
0
 

Expert Comment

by:SpideyMod
ID: 8020381
per recommendation

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now