中央目录项未找到(抛出:Zip​​Exception) [英] Central Directory Entry not found (ZipException)

查看:1996
本文介绍了中央目录项未找到(抛出:Zip​​Exception)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想下载的zip文件到SD卡。我没有下载它,但是当我打开下载的文件(用的ZipFile)我得到这个抛出:Zip​​Exception(中央目录项没有找到)。

I am trying download zip file to SD card. I download it correctly, but when I open downloaded file (with ZipFile) I get this ZipException ("Central Directory Entry not found").

互联网文件是好的,SD拷贝文件是好的(从PC上打开并显示正确的文件),但由于某种原因不能在Android的工作。

Internet-file is okay, SD-copy-file is okay (from PC opened and show files correctly), but for some reason don't work in Android.

code下载:

BufferedInputStream stream = null;
try {
  stream = new BufferedInputStream(is, 8192);
}
....

尝试{   ByteArrayBuffer BAF =新ByteArrayBuffer(50);   INT电流= 0;   而((电流= stream.read())!= - 1)     baf.append((字节)电流);

try { ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = stream.read()) != -1 ) baf.append((byte) current);

的BufferedOutputStream FOS =新的BufferedOutputStream(新的FileOutputStream(路径));   fos.write(baf.toByteArray());   fos.close(); } ...

BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(path)); fos.write(baf.toByteArray()); fos.close(); } ...

我supossed这个问题是在ZIP文件头,这是不正确写的,但我不知道出于什么原因,确实。 Ç的ZipEntry类的源$ C ​​$显示我:

I supossed that the problem is in the ZIP file headers, which was not properly written, but I do not know for what reason. The source code ZipEntry class shows me this:

long sig = (hdrBuf[0] & 0xff) | ((hdrBuf[1] & 0xff) < <  8) |
           ((hdrBuf[2] & 0xff) < <  16) | ((hdrBuf[3] < <  24) & 0xffffffffL);
if (sig != CENSIG) {
     throw new ZipException("Central Directory Entry not found");
}

谢谢

推荐答案

自动应答:问题是,HTTP请求使用接受编码:gzip压缩

Auto-answer: The problem was that HTTP request use Accept-Encoding: gzip.

服务器返回的信息已经融为一体pressed文件并下载,DECOM preSS它,去掉头部的一部分。

The server returned an already compressed file and download it, decompress it, removing part of the header.

不幸的是,7zip的正确打开(可能是,不检查头),而Android无法打开文件(可能是,检查头)。

Unfortunately, 7zip opened correctly (probably, not check headers), but Android not open file (probably, check headers).

简单:小心,并与一些文件,检查文件正确编码

In short: Be careful, and check correctly file-encoding with some files.

这篇关于中央目录项未找到(抛出:Zip​​Exception)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆