Module java.base
Package java.util.zip

Class ZipInputStream

java.lang.Object
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
JarInputStream

public class ZipInputStream extends InflaterInputStream
An input stream for reading compressed and uncompressed ZIP file entries from a stream of bytes in the ZIP file format.

Reading Zip File Entries

The getNextEntry() method is used to read the next ZIP file entry (Local file (LOC) header record in the ZIP format) and position the stream at the entry's file data. The file data may read using one of the ZipInputStream read methods such as read or readAllBytes(). For example:
  Path jar = Path.of("foo.jar");
  try (InputStream is = Files.newInputStream(jar);
       ZipInputStream zis = new ZipInputStream(is)) {
      ZipEntry ze;
      while((ze= zis.getNextEntry()) != null) {
         var bytes = zis.readAllBytes();
         System.out.printf("Entry: %s, bytes read: %s%n", ze.getName(),
                 bytes.length);
      }
  }
API Note:
The LOC header contains metadata about the Zip file entry. ZipInputStream does not read the Central directory (CEN) header for the entry and therefore will not have access to its metadata such as the external file attributes. ZipFile may be used when the information stored within the CEN header is required.
Since:
1.1