Friday, February 15, 2008

Java: how to find the absolute path with white space to the resource ?

For example: our program contains the resource A and class MyClass


src
main
java
MyClass
resource
A


When we package our program, A will be at root.
To get the absolute path to resource(for example when we want to do unit test
and load those resource for test), we will call
String path = MyClass.getClass.GetResource("/A").toURI().getPath();
And now we have the absolute path to resource.

Google