0

I have a problem where I can't seem to link to a xml file, see the layout below:

Folder Name
-Folder
-Folder
-SourceFiles
   -packagename
       -all my java files
-myXml.xml

Build is where all the class files etc is stored.
src is where the projectFolder is, and within it the java files

Code I am using to link XML File for Synth: SynthDialog.class.getResourceAsStream("synthtest/synthDemo.xml")

Now I want to link to the myXML.xml file in the top-level folder. It would be the PHP Equivelent of ../../Folder/

Thanks

2 Answers 2

1

You appear to be attempting to access the file using getResourceAsStream with a relative name. If that is the case, then the resource should be in located in a JAR file or directory on the classpath, and the location will be resolved relative to the FQN of the class.

I can't tell where the ".class" files are located in the tree, or how your classpath is set up, so I can't be more specific.


UPDATED

If you are executing out of that build directory, then your build process needs to copy the XML file to the appropriate place in the build tree so that the class-relative path ends up referring to the file. (Or use a path that starts with "/" so that you don't depend on the classes FQN at all.)

In the long term, you will probably execute out of a JAR file, and the data file will need to be inside it.

Sign up to request clarification or add additional context in comments.

1 Comment

Please see my post now for more info please
0

Use "getSystemResourceAsStream" instead of "getResourceAsStream" to access files outside of your codebase.

2 Comments

Ok, but how would I link to the file then, the complete c:// etc or how?
Ultimately, you need a qualified path, as your relative path would probably be relative to JAVA_HOME/bin. I would recommend appending your relative path to a variable that holds the current directory of your context (e.g. using getContextPath() off your Request object).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.