How to read Jar files in Java

Jar files are ways of packaging Java classes and sources at times. We might at times need to read the Jar files and process the contents. Let’s see how to read Jar Files in Java

Let’s quickly see the code

To read a Jar file, we need to use JarInputStream. Each Entry within a Jar is represented by a JarEntry object. Once we get hold of JarInputStream, we need to iterate through it till we get JarEntry. Here we just output the name and compressed size. In real life, we can add custom processing on each JarEntry.

Leave a Reply

Your email address will not be published. Required fields are marked *