I need to look at the file names inside a specific package. I am currently doing the following:
ClassLoader loader = Thread.currentThread().getContextClassLoader();
URL packageUrl = loader.getResource(getPackage().replace('.', '/'));
File packageDir = new File(packageUrl.getFile());
This really works fine in Eclipse, because by default it does not pack my application. However, when I run it from the jar file, I get NullPointerExceptionon packageUrl.
So, how do I get a list of package contents inside a jar? My research suggested using it getResourceAsStream, but I'm not quite sure how to research the directory with InputStream, if possible.
source
share