I\'m writing the FILEPATH parameter into the properties file like below..
String newFilePath = txtFilepath.getText();
Properties prop = new Prop
Backslash \
is an escape character that is silently dropped in not followed by another \
Colon :
is a special character that must by escaped with \
.
Check docs at
http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html
Just call prop.get("FILEPATH")
. You will see that you get back "D:\filelog.txt", just as you put it in.
In a properties file, :
has a meaning.
key = value
key: value
both are valid. Hence, it has to be escaped while writing to a properties file. Even \
needs escaping. But when you display them on the console, the escaping is identified, and the values are shown properly.
If you see the docs of store() method of the Properties
class
Every entry in this Properties table is written out, one per line. For each entry the key string is written, then an ASCII =, then the associated element string. Each character of the key and element strings is examined to see whether it should be rendered as an escape sequence. The ASCII characters \, tab, form feed, newline, and carriage return are written as \, \t, \f \n, and \r, respectively. Characters less than \u0020 and characters greater than \u007E are written as \uxxxx for the appropriate hexadecimal value xxxx. For the key, all space characters are written with a preceding \ character. For the element, leading space characters, but not embedded or trailing space characters, are written with a preceding \ character. The key and element characters #, !, =, and : are written with a preceding backslash to ensure that they are properly loaded.
Note:- It shouldn't be a problem if you use Properties
to read the properties file(it will handle the escaping), but if you read the properties file like a normal text file(you should never do it unless you're out of your mind), then it'll be a problem.