Replacing backslash with double backslash
This is a juvenile problem and too Microsofty. The problem is when Windows-based file names has been stored in a properties file in this way:
When retrieving that value, the backslashes will be dropped during
Sometimes we have GUI-based configuration managers that we like to be able to store in a properties file or an XML file but want to retrieve the file names with desirable results. Therefore our configuration should look like this:
In order to achieve that, we can use a 2-liner code with JDK's Regular Expression API like this one:
The code above will yield
my.file=C:\Windows\Kamote
When retrieving that value, the backslashes will be dropped during
Properties.load()
execution so the resulting string will be:C:WindowsKamote
Sometimes we have GUI-based configuration managers that we like to be able to store in a properties file or an XML file but want to retrieve the file names with desirable results. Therefore our configuration should look like this:
my.file=C:\\Windows\\Kamote
In order to achieve that, we can use a 2-liner code with JDK's Regular Expression API like this one:
String path = "C:\Windows\Kamote";
String newPath = path.replaceAll("\\\\", "\\\\\\\\");
The code above will yield
C:\\Windows\\Kamote
. This code is not really necessary, it's just a convenience fix for Windows dummies.
Comments
my.file=C:/Windows/Kamote
this should be better
Xemacs/emacs on windows can read bother forward/back slashes -- that's very convenient.
I use sed to do my regexes inside of batch files.
BR,
~A