I would like just to extract a normal zip file, but it keeps failing.
This is my code I'm using now:
private File downloadPath = new File(Environment.getExternalStorageDirectory() + "/Test/file.zip");
private File unzipLoc = new File(Environment.getExternalStorageDirectory() + "/Test/");
FileInputStream fin = new FileInputStream(downloadPath);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null)
{
FileOutputStream fout = new FileOutputStream(unzipLoc + ze.getName());
for (int c = zin.read(); c != -1; c = zin.read())
{
fout.write(c);
}
zin.closeEntry();
fout.close();
}
zin.close();
It fails on the 'zin.getNextEntry()' part.
Error: java.util.zip.ZipException: Cannot read version
Any ideas? Thx!
解决方案
Looks like your zip file is newer than your 'unzipping library'.
If you read the source:
ZipInputStream (search for new ZipException("Cannot read version"))
It shows you it checks the zip files version. Then looking at Wikipedia it shows this is the minimum version needed to extract the zip.
Check your zip file and re-save it with a lower version of your zip software / zip it again with no compression to test
Alternately update your Zip library (which you can't do as your using the internal android zip library).