Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unexpected end of ZLIB input stream

807601Jun 12 2008 — edited Jun 12 2008
Hi Experts,

I have to write a simple code that unziped the files within folders.
While running the code - folders are created and some files unziped properly. but latter on it gives an error: Unexpected end of ZLIB input stream

Below is my code. Please tell me whats wrong with this?
Please reply as soon as possible, its urgent.
<%@ page language="java" import="java.io.File,java.io.FileWriter,java.util.*,java.io.*,java.util.zip.*"%>
<%

    String xlsname="",fname="";
    String path="D:/mike/source";
    
    try
    {
        int BUFFER = 2048;
        BufferedOutputStream dest = null;
        FileInputStream fis = new FileInputStream("D:/mike/source/new200.zip");
        ZipInputStream zip = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry = zip.getNextEntry();
        
        while((entry = zip.getNextEntry()) != null) 
        {
            System.out.println("Extracting: " +entry);
            if ((entry.isDirectory()))
            {
                fname=entry.getName();
                (new File(path+"/"+entry.getName())).mkdir();
                continue;
            }
            else
            {
                int countm;
                byte datam[] = new byte[BUFFER];
                // write the files to the disk
                FileOutputStream fosm = new FileOutputStream(path+"/"+entry.getName());
                dest = new  BufferedOutputStream(fosm, BUFFER);
                while ((countm = zip.read(datam, 0, BUFFER)) > -1)
                {
                   dest.write(datam, 0, countm);
                }
                dest.flush();
                dest.close();
            }
        }
           // zip.closeEntry(); 
            zip.close();
        
      } catch(Exception zip) {
        System.out.println("Error "+zip);
      }
    
%>
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 10 2008
Added on Jun 12 2008
6 comments
7,774 views