Skip to Main Content

Java Programming

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!

Zipping files produces 0 byte file

679826Jan 20 2009 — edited Jan 20 2009
This code generates a 0 byte *.zip file and doesn't throw any errors. BUFFER is set at 20480. What am I doing wrong?
    private void zipEm()
  {
    File directory = new File(_imageFolderPath);
    String files[] = directory.list();

    try {
      BufferedInputStream origin = null;
      FileOutputStream dest = new FileOutputStream(_zipFilePath);
      ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(dest));
      
      byte data[] = new byte[BUFFER];
      
      File f = null;
      ZipEntry entry = null;
      FileInputStream fi = null;
      int count;
      
      for (int i=0; i <files.length; i++)
      {
        fi = new FileInputStream(files);
origin = new BufferedInputStream(fi, BUFFER);
entry = new ZipEntry(files[i]);
zip.putNextEntry(entry);

while((count = origin.read(data,0,BUFFER)) != -1)
{
zip.write(data,0,count);
}
count = 0;
origin.close();
}
zip.close();
}
catch (Exception e)
{
// handle exception
e.printStackTrace();
}
}
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 17 2009
Added on Jan 20 2009
7 comments
586 views