You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@felix.apache.org by Shamik Bandopadhyay <sh...@gmail.com> on 2011/07/08 01:23:40 UTC
How to get absolute path of a classpath resource
Hi,
I'm struggling to get the absolute file / dir path of files / directories
located under project's resource folder. The file paths are injected through
spring as :
<property name="siteConfig" value="classpath:/Test/test.xml" />
<property name="siteDir" value="classpath:/Test/Sample" />
The directory is located under src/main/resources folder, which makes it
available as a classpath resource inside the bundle.
The property is being set as a Spring Resource object the java class. I'm
trying to access the file following way :
File testFile = new File(this.siteConfig.getURL().getPath());
I'm passing this File object to another program which then reads it.
Here are some of the values from the two file objects :
Here's the URI of siteConfig --> bundle://249.14:1/TEST/test.xml
testFile absolute path --> C:\TEST\test.xml . As you can see, the absolute
path is just repalcing "bundle://249.14:1" with "C:\", which is incorrect.
As a result, when the program is trying to read the file, its not able to
pick it up. The absolute path shoould be
"C:\TestProject\src\main\resources\TEST\text.xml"
I'm not able to figure how to get the absolute file.
Any pointers will be appreciated.
- Thanks