Skip to Main Content

New to Java

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!

escape "\" by "\\ and "/" by "// before storing properties file

807597May 20 2005 — edited Jun 19 2006
Hi:

I am manipulating an existing properties file by replacing a value of property in it.
This file contains several directory separatorr "/" for Unix and "\" for Windows in it.
After I load the file, set the property value and before I store the file, I want to replace all occurences of "\" by "\\ and "/" by "//" in th file and thereafter store it. If I do not do this, then I see java.lang.illegalArgumentException: Malformed \uxxxx enconding.
How can I do this?

Properties props = new Properties();
try
{
props.load(new FileInputStream(file));
}
catch(IOException ioe)
{
}

props.setProperty("key","val");

//add code to replace "/" by "//" and "\" by "\\"

try
{
props.store(new FileOutputStream(file));
}
catch()
{
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 17 2006
Added on May 20 2005
19 comments
600 views