开发者

Unziping files with ZIpFile

开发者 https://www.devze.com 2023-03-05 15:18 出处:网络
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!

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号