How to read a file from a jar file?

If your jar is on the classpath:

InputStream is = YourClass.class.getResourceAsStream("1.txt");

If it is not on the classpath, then you can access it via:

URL url = new URL("jar:file:/absolute/location/of/yourJar.jar!/1.txt");
InputStream is = url.openStream();

Leave a Comment