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);
}
%>