Project root folder path
20,855
Turns out Eclipse puts the entire content of the res
folder in the root folder of the bin
folder. Therefore the path is just very simply /file.xml
. I tried putting it into a subfolder of res called xmls
and the path then is /xmls/file.xml
I also went to the source tab of the java build path and added the res folder.
Author by
Killerpixler
Updated on October 22, 2020Comments
-
Killerpixler over 3 years
I have a class in a package com.mwerner.utils that needs the path for an
getResourceAsStream()
callthe file it is supposed to load is located in a subfolder of the project root i.e.:
/src/com/mwerner/utils/myfile.java has to load
/res/file.xml
I tried stuff like
/res/file.xml ../res/file.xml res/file.xml
What is the right one?
EDIT:
I am using Xstream to parse the XML into objects. The line of code in question is:
ObjectInputStream in = xstream.createObjectInputStream(Utils.class.getResourceAsStream("res/file.xml"));
I get an
IOException
withunknown source
-
Daniel over 10 yearsI dont't know how the code is executed, but try to add these lines
Path currentRelativePath = Paths.get("");
String s = currentRelativePath.toAbsolutePath().toString();
System.out.println("Current relative path is: " + s);
This should print out the current folder -
Behe over 10 yearsWhat did you try and what happened?
-
Viktor Seifert over 10 yearsSo the 'src' and 'res' directories are located in the same parent directory?
-
Killerpixler over 10 yearswell the src folder is where eclipse stores the source code, the res folder is - like the src folder - in the root of the project, i.e. would be in the root of the JAR that i'd package for distribution
-