I'm using the following code to unzip files.
I'm catching this exception "unZip()=java.io.IOException", but the file is decompressed and created!
Any ideas?
Thanks.
public boolean unZipPage(int page)
{
try
{
File 开发者_如何转开发f=new File(zippagename);
FileOutputStream out = new FileOutputStream(f);
ZipEntry fh=fhs.get(page);
InputStream is = zif.getInputStream(fh);
byte buf[] = new byte[1024];
int numread;
while((numread = is.read(buf,0,1024))>=0)
{
out.write(buf, 0, numread);
}
is.close();
out.flush();
out.close();
}
return true;
}
catch (FileNotFoundException e)
{
Log.v("comicsZip", "unZip()=" + e);
}
catch (IOException e)
{
Log.v("comicsZip", "unZip()=" + e + " Page="+page);
}
return false;
}
The problem might be closing the input. It should only be done once at the end for the entire ZipInputFile (I assume that's what 'zif' is) and not after each ZipEntry is processed.
精彩评论