Load resource file: relative to the class location : Class Path « Development Class « Java






Load resource file: relative to the class location

 
import java.io.IOException;
import java.net.URL;

public class Main {
  public static void main(String[] args) throws IOException {
    // relative to the class location
    URL url = Main.class.getResource("foo.txt");
  }
}

   
  








Related examples in the same category

1.getClass().getResourceAsStream
2.Try adding one or more item(s) to class path
3.Load resource file: absolute from the classpath
4.relative document loading in classpath
5.Self ClassLoader