title: Java - Zipping existing files
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2223434/appending-files-to-a-zip-file-with-java">Appending files to a zip file with Java</a>  </p>
  </blockquote>
  
  
  
  <p>Hello Java Developers,</p>
  
  <p>Here's the scenario:<br><br>
  Say I have a textfile named <code>sample.txt</code>. What I actually want to do is to put the <code>sample.txt</code> file into a <code>*.zip</code> file named <code>TextFiles.zip</code>.<br><br>
  Here's  what I have learned so far.</p>
  
  <pre><code>try{
      File f = new File(compProperty.getZIP_OUTPUT_PATH());
      zipOut = new ZipOutputStream(new FileOutputStream(f));
      ZipEntry zipEntry = new ZipEntry("sample.txt");
      zipOut.putNextEntry(zipEntry);
      zipOut.closeEntry();
      zipOut.close();
      System.out.println("Done");
  
  } catch ( Exception e ){
      // My catch block
  }
  </code></pre>
  
  <p>My code so far creates a <code>*.zip</code> file and insert the <code>sample.txt</code> file.<br>
  My question is how would I be able to insert an existing file to the created <code>*.zip</code> file?<br>
  If your answer has anything to do with <a href="http://truezip.java.net/6/index.html" rel="nofollow noreferrer">TrueZIP</a>, please post an SSCCE.<br><br>
  I have done the following:<br></p>
  
  <ul>
  <li>Googled</li>
  <li>Search for existing question. ( Found few. No answer. Some didn't answer my particular question.</li>
  <li>Read <a href="http://truezip.java.net/6/index.html" rel="nofollow noreferrer">TrueZip</a>. Yet, I couldn't understand a thing. ( Please do understand )</li>
  </ul>