2

I am not sure if a URLClassLoader can be used. Also, only the relative path of the XML is known.

Thank You.

1
  • Add XML file to what, exactly? Commented Dec 29, 2008 at 10:44

1 Answer 1

2

If you just mean read in an XML file that is already on the classpath, so that you can parse it using whatever library you prefer, the most compact way is using a ClassLoader:

InputStream is = ClassLoader.getResourceAsStream();
// use the input stream however you want
is.close()

See http://java.sun.com/javase/6/docs/api/java/lang/ClassLoader.html

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

Comments

Your Answer

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