java zip文件头信息,解压压缩文件给" java.util.zip.ZipException:无法读取版本"或QUOT; java.util.ZipException无法读取...

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).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值