Java Properties backslash

It is Properties.load() that’s causing the problem that you are seeing as backslash is used for a special purpose.

The logical line holding all the data
for a key-element pair may be spread
out across several adjacent natural
lines by escaping the line terminator
sequence with a backslash character,
\.

If you are unable to use CoolBeans’s suggestion then what you can do is read the property file beforehand to a string and replace backslash with double-backslash and then feed it to Properties.load()

String propertyFileContents = readPropertyFileContents();

Properties properties = new Properties();
properties.load(new StringReader(propertyFileContents.replace("\\", "\\\\")));

Leave a Comment