4 Replies Latest reply: Sep 28, 2008 10:24 AM by 843785 RSS

    All zip files turn out as empty text/plain files

    843785
      I'm trying to run a jsp that extracts a zip file. It seems to work fine, but when you look at the extracted files, all the directories are text/plain and only the directories in the zip file's root are written, as it returns FileNotFoundException when trying to write to a subdir, because it isn't a subdir.

      This is the code I am using:
      <%
      final int BUFFER = 2048;
            try {
               BufferedOutputStream dest = null;
               FileInputStream fis = new FileInputStream("/absolute/path/to.zip");
               ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
               ZipEntry entry;
               while((entry = zis.getNextEntry()) != null) {
                  %><p>Extracting: <%=entry%></p><%
                  int count;
                  byte data[] = new byte[BUFFER];
                  // write the files to the disk
                  FileOutputStream fos = new FileOutputStream("/absolute/path/to/extract/" +entry.getName());
                  dest = new BufferedOutputStream(fos, BUFFER);
                  while ((count = zis.read(data, 0, BUFFER)) != -1) {
                     dest.write(data, 0, count);
                  }
                  dest.flush();
                  dest.close();
               }
               zis.close();
            } catch(Exception e) {
               e.printStackTrace();
            }
      %>
      from http://java.sun.com/developer/technicalArticles/Programming/compression/

      Could I narrow this down to be a software related issue, or is it something in the code?

      Software:
      Fedora 9
      OpenJDK 1.6.0
      Tomcat 6 (bundled in Netbeans 6.1)