title: writing a string to a zip file using ZipOutputStream
body: <p>Ultimately the goal is just to zip a string and have that as a string in java</p>
  <pre><code> public void zip() {
      try {
        String myTestString = &quot;a zip file test and another test&quot;;
        InputStream in = new ByteArrayInputStream(myTestString.getBytes());
        OutputStream out = new ByteArrayOutputStream();
        ZipOutputStream zipOut = new ZipOutputStream(out);
        ZipEntry zipEntry = new ZipEntry(&quot;wtf.txt&quot;);
        zipOut.putNextEntry(zipEntry);
        zipOut.write(myTestString.getBytes(),0,myTestString.getBytes().length);
        zipOut.close();
        myTestString = out.toString();
        out.close();
        System.out.println(myTestString);
        
      
        // just a test if I can read the file 
        in = new ByteArrayInputStream(myTestString.getBytes());
        out = new FileOutputStream(&quot;c:\\t\\string.zip&quot;);
        byte[] allBytes = new byte[(int) myTestString.getBytes().length];
        in.read(allBytes);
        out.write(allBytes);
        out.close();
        
        
      } catch (IOException e) {
        e.printStackTrace();
      }
      
    }
  </code></pre>
  <p>I have found I can write a string to a zipfile using</p>
  <pre><code>  public void zipStringToFile2() {
      try {
        FileOutputStream fos = new FileOutputStream(&quot;c:/t/compressed.zip&quot;);
        ZipOutputStream zipOut = new ZipOutputStream(fos);
        String myTestString = &quot;a zip file test and another test&quot;;
        int buffer = myTestString.getBytes().length;
  //      byte[] myBytes = myTestString.getBytes();
        ByteArrayOutputStream out = new ByteArrayOutputStream(buffer);
        ZipEntry zipEntry = new ZipEntry(&quot;wtf.txt&quot;);
        zipOut.putNextEntry(zipEntry);
        zipOut.write(myTestString.getBytes(),0,buffer);
        zipOut.close();
        fos.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  </code></pre>
  <p>but I cannot get the output of zipOut to write to a string and then have the string write to a file and then via the OS open the zipfile. How can that be done?</p>