commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject file upload and unzip
Date Tue, 23 Aug 2005 07:34:30 GMT
Dear all 

I would like to get your input again on the subject of handling an
uploaded zip file in tomcat 

I have tried to follow some suggestions from the list with no luck so
far ( I still get the same results).

I am trying to upload the file into tomcat and use the .getInput stream
from the FileItem  to handle the file. 

The following methods decompress the zipped content into a file space on
my server. 

The result I am getting baxk from tomcat is that it cannot handle the
zip file because some file stream is still open. 

As far as I have checked in my code there are no open streams left. Is
it possible that some stream is pending from the upload libs? 


Thanks for your time 

And help in advanced 


public void decompress(String destFolder, String file, InputStream
inputStream) throws IOException {
  ZipInputStream zis=new ZipInputStream(inputStream);
  ZipFile zf=new ZipFile(this.getFile());
     ZipEntry ze;
  while(( ze=zis.getNextEntry())!=null){
  //ZipEntry ze = zf.getEntry(file.getName());
   //System.out.println ("unzipping: " +ze.getName());


synchronized void processEntry( ZipEntry ze,String destFolder,
InputStream ins)throws IOException
//  get zip entry
//  get an input stream for the entry
      //and an output stream
      File outFile = new File(destFolder+"/"+ze.getName());
      FileOutputStream fos = new FileOutputStream(outFile); 
      int bread;
//  transfer buffer
      byte[] bin = new byte[4096];            

      //loop through reading the zipped file entry and
      // write it to the external file
      //System.out.println("writing output to
      while ( (bread =, 0, 4096)) > -1) {
        fos.write(bin, 0, bread);


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message