我正在尝试将 zip 文件下载到 SD 卡。我正确下载了它,但是当我打开下载的文件(使用 ZipFile)时,我得到了这个 ZipException(“找不到中央目录条目”)。
Internet-file 没问题,SD-copy-file 没问题(从 PC 打开并正确显示文件),但由于某种原因在 Android 中不起作用。
下载代码:
BufferedInputStream stream = null;
try {
stream = new BufferedInputStream(is, 8192);
}
....
try {
ByteArrayBuffer baf = new ByteArrayBuffer(50);
int current = 0;
while ((current = stream.read()) != -1 )
baf.append((byte) current);
BufferedOutputStream fos = new BufferedOutputStream(new FileOutputStream(path));
fos.write(baf.toByteArray());
fos.close();
}
...
我认为问题出在 ZIP 文件头中,它没有正确写入,但我不知道是什么原因。源代码 ZipEntry 类向我展示了这一点:
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");
}
谢谢,