Class: getResource(String name) (absolute from the classpath)
import java.net.URL; public class MainClass { public static void main(String[] args) throws Exception { // absolute from the classpath URL url = MainClass.class.getResource("/mypackage/foo.txt"); System.out.println(url); // relative to the class location url = MainClass.class.getResource("foo.txt"); System.out.println(url); // another relative document url = MainClass.class.getResource("docs/bar.txt"); System.out.println(url); } }