title: Java.util.zip adding a new file overwrites entire jar?
body: <p>I am using java.util.zip to add some configuration resources into a jar file.
  when I call addFileToZip() method it overwrites the jar completely, instead of adding the file to the jar.  Why I need to write the config to the jar is completely irrelevant.  and I do not wish to use any external API's.</p>
  
  <p>EDIT: The jar is not running in the VM and org.cfg.resource is the package I'm trying to save the file to, the file is a standard text document and the jar being edited contains the proper information before this method is used.</p>
  
  <p>My code:</p>
  
  <pre><code>public void addFileToZip(File fileToAdd, File zipFile)
  {
      ZipOutputStream zos = null;
      FileInputStream fis = null;
      ZipEntry ze = null;
      byte[] buffer = null;
      int len;
  
      try {
          zos = new ZipOutputStream(new FileOutputStream(zipFile));
      } catch (FileNotFoundException e) {
      }
  
      ze = new ZipEntry("org" + File.separator + "cfg" + 
              File.separator + "resource" + File.separator + fileToAdd.getName());
      try {
          zos.putNextEntry(ze);
  
          fis = new FileInputStream(fileToAdd);
          buffer = new byte[(int) fileToAdd.length()];
  
          while((len = fis.read(buffer)) &gt; 0)
          {
              zos.write(buffer, 0, len);
          }           
      } catch (IOException e) {
      }
      try {
          zos.flush();
          zos.close();
          fis.close();
      } catch (IOException e) {
      }
  }
  </code></pre>