Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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!

like image 915
ovdsrn Avatar asked Mar 04 '11 20:03

ovdsrn


People also ask

How do I put the file path in a property file?

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.

How do you specify a file path in Java program?

The path for a file can be obtained using the method java. io. File. getPath().


1 Answers

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!

like image 53
Eugene Ryzhikov Avatar answered Oct 06 '22 00:10

Eugene Ryzhikov