Access file in jar file?

You could use something like this:

InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileFromJarFile);

If foo.txt was in the root of your JAR file, you’d use:

InputStream is = this.getClass().getClassLoader().getResourceAsStream("foo.txt");

assumes the class is in the same JAR file as the resource, I believe.

Leave a Comment