//file: FindResources.java
package mypackage;
import java.net.URL;
import java.io.IOException;
public class FindResources {
public static void main( String [] args ) throws IOException {
// absolute from the classpath
URL url = FindResources.class.getResource("/mypackage/foo.txt");
// relative to the class location
url = FindResources.class.getResource("foo.txt");
// another relative document
url = FindResources.class.getResource("docs/bar.txt");
}
}
|