4 Replies Latest reply on Sep 28, 2008 3:24 PM by 843785

    All zip files turn out as empty text/plain files

      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);
            } catch(Exception e) {
      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?

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