title: how to provide download option for the dynamically generated file in java
body: <p>I am creating pdf file using jasper reports. The code for generating the pdf file runs fine and the file is created on a specified path. But I want the file to be downloaded rather than to be stored on some drive of a client. I use word dynamically in my question because it is generated from jasper reports when user clicks on download. I googled for this and I got that response.setHeader is responsible for downloading but it needs a source or we can say that path of the storage. The code for generating pdf is given below.</p>
  
  <pre><code>String ip="D:\\workspace\\Jsaper1\\src\\Coll.jasper";
      String op="D:\\workspace\\Jsaper1\\src\\Timesheet.pdf";
  
  
      try
      {
          File file=new File(ip);
          InputStream is=new FileInputStream(file);
           Map&lt;String, Object&gt; params = new HashMap&lt;String, Object&gt;();
          Datasource da=new Datasource();
          JRDataSource jrdsource=new JRBeanCollectionDataSource(da.getDataSource());
  
  
          JasperReport jreport=(JasperReport) JRLoader.loadObject(file);
  
          JasperPrint jasperPrint = JasperFillManager.fillReport(jreport, params, da.getDataSource1());
  
          JasperExportManager.exportReportToPdfFile(jasperPrint, op);   
  
                  sos.flush();
          sos.close();
      }
      catch(Exception e)
      {
          e.printStackTrace();
      }
  </code></pre>