Saturday, August 18, 2012

Using File Resources

Loading a file in Java should be done through, either:
Class.getResource()
Class.getClassLoader().getResourceAsStream();

These two vary in the way they locate the file.
Class.getResource() searches file relative to package location of the class.

ClassLoader search happens by delegating the findResource to parent ClassLoader before this classloader itself does try. Specifying absolute path does not work.

No comments:

Post a Comment