title: How to return zip from bytearray on Servlet
body: <p>working again with Java EE.</p>
  
  <p>In example</p>
  
  <ol>
  <li>On servlet I have byte[] fileContent ---->(file.txt)</li>
  <li>I try to add it to zip file</li>
  <li><p>set servlet as</p>
  
  <pre><code>response.setContentType("Content-type: text/zip");
  response.setHeader("Content-Disposition",
          "attachment; filename=mytest.zip");
  
  // List of files to be downloaded
  List files = new ArrayList();
  files.add(new File("C:/first.txt"));
  
  ServletOutputStream out = response.getOutputStream();
  ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(out));
  
  for (File file : files) {
  
      System.out.println("Adding " + file.getName());
      zos.putNextEntry(new ZipEntry(file.getName()));
  
      // Get the file
      FileInputStream fis = null;
      try {
          fis = new FileInputStream(file);
  
      } catch (FileNotFoundException fnfe) {
          // If the file does not exists, write an error entry instead of
          // file
          // contents
          zos.write(("ERRORld not find file " + file.getName())
                  .getBytes());
          zos.closeEntry();
          System.out.println("Couldfind file "
                  + file.getAbsolutePath());
          continue;
      }
  
      BufferedInputStream fif = new BufferedInputStream(fis);
  
      // Write the contents of the file
      int data = 0;
      while ((data = fif.read()) != -1) {
          zos.write(data);
      }
      fif.close();
  
      zos.closeEntry();
      System.out.println("Finishedng file " + file.getName());
  }
  
  zos.close();
  </code></pre>
  
  <p>}
  }</p></li>
  </ol>
  
  <p>I have problem with the second point. I try several of solutions but all of them hardly working with my servlet or didn't work.</p>
  
  <p>Could somebody show me on example how add file as array of bytes to zip and return on servlet as atachment? Thanks for any tips and advices</p>
  
  <p>--post edit</p>
  
  <p>I try something like that, but how can I add byte[] instead of file.</p>