← 返回首页
ZipInputStream (Java SE 26 & JDK 26)
JavaScript is disabled on your browser.
Contents  
  1. Description
    1. Reading Zip File Entries
  2. Field Summary
    1. Fields declared in class InflaterInputStream
    2. Fields declared in class FilterInputStream
  3. Constructor Summary
  4. Method Summary
    1. Methods declared in class InflaterInputStream
    2. Methods declared in class FilterInputStream
    3. Methods declared in class InputStream
    4. Methods declared in class Object
  5. Field Details
    1. LOCSIG
    2. EXTSIG
    3. CENSIG
    4. ENDSIG
    5. LOCHDR
    6. EXTHDR
    7. CENHDR
    8. ENDHDR
    9. LOCVER
    10. LOCFLG
    11. LOCHOW
    12. LOCTIM
    13. LOCCRC
    14. LOCSIZ
    15. LOCLEN
    16. LOCNAM
    17. LOCEXT
    18. EXTCRC
    19. EXTSIZ
    20. EXTLEN
    21. CENVEM
    22. CENVER
    23. CENFLG
    24. CENHOW
    25. CENTIM
    26. CENCRC
    27. CENSIZ
    28. CENLEN
    29. CENNAM
    30. CENEXT
    31. CENCOM
    32. CENDSK
    33. CENATT
    34. CENATX
    35. CENOFF
    36. ENDSUB
    37. ENDTOT
    38. ENDSIZ
    39. ENDOFF
    40. ENDCOM
  6. Constructor Details
    1. ZipInputStream(InputStream)
    2. ZipInputStream(InputStream, Charset)
  7. Method Details
    1. getNextEntry()
    2. closeEntry()
    3. available()
    4. read()
    5. readAllBytes()
    6. readNBytes(int)
    7. readNBytes(byte[], int, int)
    8. skipNBytes(long)
    9. transferTo(OutputStream)
    10. read(byte[], int, int)
    11. skip(long)
    12. close()
    13. createZipEntry(String)
Hide sidebar  Show sidebar

Class ZipInputStream

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.

Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

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:
Copy 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

Scripting on this page tracks web page traffic, but does not change the content in any way.