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

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


This is a known issue with the android ZipFile implementation:

http://code.google.com/p/android/issues/detail?id=23207

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 C64Music.zip 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: http://commons.apache.org/compress/apidocs/org/apache/commons/compress/archivers/zip/ZipFile.html


    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));         out.putNextEntry(entry);         int count;         while ((count = origin.read(data, 0, BUFFER)) != -1) {           out.write(data, 0, count);         }         origin.close();       }       out.close();     } catch(Exception e) {       e.printStackTrace();     }   } }Call Compress like given below where you want to zip a file  :----String zipFilePath = "fileName.zip";File zipFile = new File(zipFilePath);String[] files = new String[] {"/sdcard/fileName"};if(!zipFile.exists()){    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.