Skip to content
Advertisement

How to specify a path in a properties file to be loaded with Java Properties

I have a .properties file I want to load in a Java Properties object. The file contains some paths. In order to be able to load the properties file without getting a java.lang.IllegalArgumentException: Malformed uxxxx encoding. when loading the properties from the file with the method Properties.load(), I need to use the escape character ” in the path.

So my path looks like: C:\Users\Harald\Folder1\Version1\Folder2. And it works this way, no exception is thrown.

The problem is that I can’t explain to my user (because this path can be changed by the user!) that he needs to use double ” in the path.

Does anybody knows a work-around for this problem? Thanks!

Advertisement

Answer

Even simpler solution is to use forward slashes. This way your path will look like C:/Users/Harald/Folder1/Version1/Folder2 and everything else will just work – no code change required!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement