0

When I try to create a java.util.zip.ZipFile I get a java.util.zip.ZipException: error in opening zip file. This exception only occurs when I try to open a large ZipFile (> 2GB). Is there a trick to open big zip files?

Later I need to extract single files from this zip and I doubt that the ZipInputStream is fast enough to extract the required files, since I need to run over all files.

Here is my StackTrace:

Caused by: java.util.zip.ZipException: error in opening zip file
   at java.util.zip.ZipFile.open(Native Method)
   at java.util.zip.ZipFile.<init>(ZipFile.java:225)
   at java.util.zip.ZipFile.<init>(ZipFile.java:148)
   at java.util.zip.ZipFile.<init>(ZipFile.java:162)

Update: I found out that it works on my desktop computer and it works if I open the ZipFile as a JUnit-Test within Android Studio, too (Since JUnit-Tests are run on the local desktop computer and not on the android device). However, I could not get it working on the android device. I guess the reason is the android file system.

Petterson
  • 803
  • 9
  • 18

1 Answers1

1

Key point to remember, especially if you are processing large zip archives is that, Java 6 only support zip file up to 2GB.

Java 7 supports zip64 mode, which can be used to process large zip file with size more than 2GB

Also using streams for big files is a good idea:

private static void readUsingZipInputStream() throws IOException {
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(FILE_NAME));
    final ZipInputStream is = new ZipInputStream(bis);

    try {
        ZipEntry entry;
        while ((entry = is.getNextEntry()) != null) {
            System.out.printf("File: %s Size %d  Modified on %TD %n", entry.getName(), entry.getSize(), new Date(entry.getTime()));
            extractEntry(entry, is);
        }
    } finally {
        is.close();
    }
Clomez
  • 1,007
  • 1
  • 10
  • 30