title: How to read Zip file from response in Java?
body: <p>I am currently working on JAX-RS, where I'm trying to send and receive Zip files. Currently for sending the zip file in response, I'm able to achieve it using the below code (verified the zip downloading by entering the URL in the browser), but I'm not clear about writing the code logic to read the Zip file from response. </p>
  
  <p>Please help me to achieve this functionality.</p>
  
  <pre><code>@GET
  @Produces({"application/zip"})
  @Path("getProduct")
  public Response getProduct() {
      String METHODNAME = "getProduct";
       if (LoggingHelper.isEntryExitTraceEnabled(LOGGER)) {
              LOGGER.entering(CLASSNAME, METHODNAME);
       }
       File file;
       try {
           Properties prop = getProp();
           file = new File(prop.getProperty("ZipLocation")+prop.getProperty("ProductZip"));
           byte[] buffer = new byte[5120];
           FileOutputStream fos = new FileOutputStream(file);
           ZipOutputStream zos = new ZipOutputStream(fos);
           ZipEntry ze= new ZipEntry(prop.getProperty("ProductOutfile"));
           zos.putNextEntry(ze);
           FileInputStream in = new FileInputStream("C:\\Documents\\ProductExtract.xml");
           int len;
           while ((len = in.read(buffer)) &gt; 0) {
               zos.write(buffer, 0, len);
           }
           in.close();
           zos.closeEntry();
           zos.close();
       } catch (FileNotFoundException ex) {
              LOGGER.logp(Level.SEVERE, CLASSNAME, METHODNAME, ex.getMessage(), ex);
              return Response.status(204).entity(ex.getMessage()).build();
       } catch (Exception ex) {
          LOGGER.logp(Level.SEVERE, CLASSNAME, METHODNAME, ex.getMessage(), ex);
          return Response.status(204).entity(ex.getMessage()).build();
       }
       return Response.ok(file, "application/zip").header("Content-Disposition", "attachment; filename=\""+file.getName()+"\"")
              .header("Content-Type", "application/zip").header("Set-Cookie", "fileDownload=true; path=/").build();
  }
  </code></pre>
  
  <p>Kindly let me know how can I achieve reading the zip file from response of the above code.</p>