Solved

retaining comment in properties file

Posted on 2002-04-17
7
279 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java.io.BufferedReader   readLine()  //returns the entire file ? 4 72
replace a word with other 1 43
Windows 10 IE Certificate Issue 10 45
java stored proc example 9 29
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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:

816 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

11 Experts available now in Live!

Get 1:1 Help Now