Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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 C64Music.zip from the HighVoltage Sid Collection. It contains over 40.000 files and is around 250MB.

I have no clue where to look at.

like image 879
wbb Avatar asked Mar 30 '12 10:03

wbb


People also ask

Can Java read ZIP files?

As of Java 7, the NIO АРI provides a better and more generic way of accessing the contents of ZIP or JAR files. Actually, it is now a unified API which allows you to treat ZIP files exactly like normal files. In order to extract all of the files contained inside of a ZIP file in this API, you'd do as shown below.

What is Java Util ZIP ZIP file?

The java. util. zip. ZipFile class is used to read entries from a zip file.

What is ZIP file Java?

ZIP is a file format for compressed files or folders. It enables data compression. Using Java programming language, we can create ZIP files or folders. For this Java provides the classes In Java, ZipFile is a class that belongs to the java.


1 Answers

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

like image 57
Luke Sleeman Avatar answered Oct 19 '22 01:10

Luke Sleeman