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!

All zip files turn out as empty text/plain files

843785Sep 28 2008 — edited Sep 28 2008
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)
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 26 2008
Added on Sep 28 2008
4 comments
371 views