This is my code:
File folder = /* the folder with a.txt file */
final URL[] urls = new URL[] {
folder.toURI().toURL()
};
ClassLoader loader = new URLClassLoader(urls);
assertThat(loader.getResource("/a.txt"), is(notNullValue()));
Doesn’t work. getResource() returns NULL. Why?
Because the resource names are always relative to the classpath you constructed the class loader with. You can’t use an absolute name (that is, one that starts with
/).