What's wrong with URLClassLoader when working with directories?
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()));
开发者_如何学C
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 /
).
精彩评论