Android 3.x+ Java ZipFile Class – Can't read ZipEntries from big files-ThrowExceptions

Exception or error:

If I open a big zip file (250MB) via the ZipFile class and try to read the entries. This works fine on 2.x in the emulator and real hardware. If I use the exact some code on my tablet (Asus Transformer running 4.0.3) or the emulator (3.2), I can’t read any entries. The size() function of the ZipFile class always returns zero and the ZipFile does not return any zip entries. Even the a zip app that comes with the ROM on my tablet can’t read any entries. The zip file is not damaged. I checked it.

The code to read from ZipFile works fine on all version with smaller zip files. What has changed between 2.x and 3.x/4.x??

My Testfile is the from the HighVoltage Sid Collection. It contains over 40.000 files and is around 250MB.

I have no clue where to look at.

How to solve:

This is a known issue with the android ZipFile implementation:

Basically zip files only support up to 65k entries. There is an extended version of the zip file format called Zip64, which supports a larger number of entries. Unfortunately ZipFile on android cannot read Zip64. You will probably find that the file is in the Zip64 format

A work around is to use the Apache Commons Compress library instead of the native implementation. Their version of ZipFile supports Zip64:


    public class Compress { 

  private static final int BUFFER = 2048;  
  private String[] _files; 
  private String _zipFile;  
  public Compress(String[] files, String zipFile) { 
    _files = files; 
    _zipFile = zipFile; 
  public void zip() { 
    try  { 
      BufferedInputStream origin = null; 
      FileOutputStream dest = new FileOutputStream(_zipFile);  
      ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); 
      byte data[] = new byte[BUFFER]; 
      for(int i=0; i < _files.length; i++) { 
        Log.v("Compress", "Adding: " + _files[i]); 
        FileInputStream fi = new FileInputStream(_files[i]); 
        origin = new BufferedInputStream(fi, BUFFER); 
        ZipEntry entry = new ZipEntry(_files[i].substring(_files[i].lastIndexOf("/") + 1)); 
        int count; 
        while ((count =, 0, BUFFER)) != -1) { 
          out.write(data, 0, count); 

    } catch(Exception e) { 



Call Compress like given below where you want to zip a file  :----

String zipFilePath = "";
File zipFile = new File(zipFilePath);
String[] files = new String[] {"/sdcard/fileName"};
    new Compress(files, zipFilePath).zip();


A lot of changes were made in 3.x/4.x to prevent abuse against the UI thread. Therefore, it is possible that your app is crashing because you are not offloading the expensive disk I/O operation to a separate Thread.

Leave a Reply

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