Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem storing special characters (\, \n etc.) in the Properties file

807569May 30 2006 — edited May 30 2006
Hello,

I am trying to store a string that contains special characters like \, \n, which are normally escaped using a \ character. If I try to save the Properties object into a file (using the store() method call), it doesn't store these escape characters as they are. The following is what I am trying to do:
Properties p = new Properties();
String samp = "This string will have a \\ and a newline \ncharacter";
p.setProperty( "sample", samp );
p.store( new FileOutputStream( "/path/to/my/file" ) );
I am trying to achieve the following result:
sample=This string will have a \ and a newline 
character
But, instead, I get this:
sample=This string will have a \\ and a newline \\\ncharacter
Can somebody help me with this problem?

Thanks,
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 27 2006
Added on May 30 2006
14 comments
889 views