0 Replies Latest reply: Oct 6, 2007 12:33 PM by 807605 RSS

    Zip does not contain files

    807605
      Hi

      I have a query regarding reading zip files created by the following class:
      class CreateZip extends Thread {
      
          CreateZip(Vector FileList) {
              try {
                  File zipFile = new File("C:/test.zip");
      
                  if (zipFile.exists()) {
                      System.err.println("Zip file already exists, please try another");
                      System.exit(0);
                  }
      
                  FileOutputStream fos = new FileOutputStream(zipFile);
                  ZipOutputStream zos = new ZipOutputStream(fos);
      
                  int bytesRead;
      
                  byte[] buffer = new byte[1024];
                  CRC32 crc = new CRC32();
      
                  for (int i=0, n=FileList.size(); i < n; i++) {
                      String name = FileList.get(i).toString();
                      File file = new File(name);
                      //Check to see whether the file already exists or whether
                      //it is not a file ie directory...
                      if (!file.exists() || !file.isFile()) {
                          System.err.println("Skipping: " + name);
                          continue;
                      }
                      BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
                      crc.reset();
                      while ((bytesRead = bis.read(buffer)) != -1) {
                          crc.update(buffer, 0, bytesRead);
                      }
                      bis.close();
                      bis = new BufferedInputStream(new FileInputStream(file));
                      ZipEntry entry = new ZipEntry(name);
                      entry.setMethod(ZipEntry.STORED);
                      entry.setCompressedSize(file.length());
                      entry.setSize(file.length());
                      entry.setCrc(crc.getValue());
                      zos.putNextEntry(entry);
                      while ((bytesRead = bis.read(buffer)) != -1) {
                          zos.write(buffer, 0, bytesRead);
                      }
                      bis.close();
                  }
                  zos.close();
      
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
      It accepts a vector which contains files and/or folders and this is supposed to add them to a zip file.
      All that happens is the zip file is created but when I open it there are no files inside that are visible. The file size does appear to grow and there are no errors generated.

      Any ideas?

      Many thanks