Reputation: 325
I'm trying to find a txt file in a separate folder to the class
C://workspace/project/src/pkg/Class.java
C://workspace/project/doc/pkg/myFile.txt
I'm trying to find the text file without having to hard code the C://workspace/project/
bit
Is this possible?
Currently I can use a classpath:/pkg/myFile.txt
when the file is in the same package as Class.java
using a resource loader
Upvotes: 0
Views: 234
Reputation: 166
You could inclide the doc folder as a source folder. That way you can keep your resources separate from the code, but still have access to it using a classloader.
Of course that will only work for you when your resource can be part of the jar. If not, you may want to consider using a properties where you can configure the complete path to the resource.
Upvotes: 1
Reputation: 514
Try getClass().getResource() or getClass().getClassLoader().getResource() if it is in the same jar-file
Upvotes: 0