dcsimg

How can I read an entry from a jar file?

John Zukowski

Basically, open the .jar file, find the entry you want, then read it:

JarFile jar = new JarFile(jarfile);
ZipEntry entry = jar.getEntry(entryname);
InputStream is = jar.getInputStream(entry);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
  System.out.println(line);
}