escape "\" by "\\ and "/" by "// before storing properties file
807597May 20 2005 — edited Jun 19 2006Hi:
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()
{
}