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").
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 for download:
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();
}
...
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");
}
Thanks,