I get it to work without any reference to "class" or "ClassLoader".
Let's say we have three scenarios with the location of the file 'example.file' and your working directory (where your app executes) is home/mydocuments/program/projects/myapp:
a)A sub folder descendant to the working directory:
myapp/res/files/example.file
b)A sub folder not descendant to the working directory:
projects/files/example.file
b2)Another sub folder not descendant to the working directory:
program/files/example.file
c)A root folder:
home/mydocuments/files/example.file (Linux; in Windows replace home/ with C:)
1) Get the right path:
a)String path = "res/files/example.file";
b)String path = "../projects/files/example.file"
b2)String path = "../../program/files/example.file"
c)String path = "/home/mydocuments/files/example.file"
Basically, if it is a root folder, start the path name with a leading slash.
If it is a sub folder, no slash must be before the path name. If the sub folder is not descendant to the working directory you have to cd to it using "../". This tells the system to go up one folder.
2) Create a File object by passing the right path:
File file = new File(path);
3) You are now good to go:
BufferedReader br = new BufferedReader(new FileReader(file));
this.getClass().getResource("/test.csv")
– Ehlers/
. However, I dogetClass().getClassLoader().getResourceAsStream(filename)
... maybe that's the difference? – Nunley