Reputation: 40203
I'm trying to open a big (around 1 GiB) zip file in Android using java.util.zip
API and get the following error:
java.lang.OutOfMemoryError
at java.util.HashMap.makeTable(HashMap.java:555)
at java.util.HashMap.doubleCapacity(HashMap.java:575)
at java.util.HashMap.put(HashMap.java:405)
at java.util.zip.ZipFile.readCentralDir(ZipFile.java:366)
at java.util.zip.ZipFile.<init>(ZipFile.java:132)
at java.util.zip.ZipFile.<init>(ZipFile.java:103)
at com.foo.bar.zip.archive.ZipArchive.<init>(ZipArchive.java:44)
I completely understand that the size of the file exceeds the memory limit by a big margin, but is there any workaround for the issue? Thanks in advance.
Upvotes: 2
Views: 1584
Reputation: 22291
Please see below link for download and extract zip files, it will solve your problem.
For Downloading Zip File:-
For Extract Zip File:-
And the zip file is make using winrar software only otherwise this will give you error.
Upvotes: 0
Reputation: 122364
Do you need to be able to extract particular entries from the zip file by name, or can you just read through the whole file once from top to bottom? If the latter you could try using ZipInputStream
rather than ZipFile
, as that doesn't need to parse the central directory up front - you can read one entry, do something with it, discard it, read the next entry, ...
Upvotes: 4
Reputation: 8030
The Java classes ZipFile
and ZipEntry
can't contain anything that is more then 613 MB of memory.
It's probably best to implement some sort of batching as you propose yourself. You could for example add up the decompressed size of each ZIP entry and upload the files every time the total size exceeds 100 MB.
Take a look at: http://truezip.java.net/
Upvotes: 4
Reputation: 533530
I suspect the problem is not the size of the file but the number of entries as it is failing when caching the Zip table entries.
Your own options are to;
Upvotes: 6
Reputation: 3088
You could try to read your file in byte arrays and partially work over it. Still it depends on what do you want to do with your file.
Upvotes: 0