user3206236
user3206236

Reputation: 325

Find resource in separate folder to class file

I'm trying to find a txt file in a separate folder to the class

Class file

C://workspace/project/src/pkg/Class.java

txt file

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

Answers (2)

DukeMe
DukeMe

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

Einar Bjerve
Einar Bjerve

Reputation: 514

Try getClass().getResource() or getClass().getClassLoader().getResource() if it is in the same jar-file

Upvotes: 0

Related Questions