title: how to download zip-file from client machine instead of opening file in browser using java?
body: <p>the given below code for downloading file to client machine. I am trying to download file to client machine using java servlet. but it's not downloaded i checked in console but no error occur</p>
  
  <p>try {</p>
  
  <pre><code>                FileInputStream fileInputStream = new FileInputStream(downloadPath);
                  response.setContentType("application/zip");
                  response.setHeader("Content-Disposition", "attachment; filename=\""+dndfilename);
                  response.setContentLength(fileInputStream.available());
                  int i;
                  while ((i = fileInputStream.read()) != -1) {
                      response.getOutputStream().write(i);
  //                  System.out.println("Result: " +i);
                  }
                  response.getOutputStream().flush();
                  response.getOutputStream().close();
                  fileInputStream.close();
  
              } catch (IOException e) {
                  e.printStackTrace();
              }
  </code></pre>