Your Ad Here

Posted By

indianocean on 04/24/08


Tagged

java servlet


Versions (?)

Download file using a servlet


 / Published in: Java
 

  1. FileInputStream fileToDownload = new FileInputStream("c:/file.xls");
  2. ServletOutputStream output = response.getOutputStream();
  3. response.setContentType("application/msexcel");
  4. response.setHeader("Content-Disposition", "attachment; filename=CombinedReportAdmin.xls");
  5. response.setContentLength(fileToDownload.available());
  6. int c;
  7. while ((c = fileToDownload.read()) != -1)
  8. {
  9. output.write(c);
  10. }
  11. output.flush();
  12. output.close();
  13. fileToDownload.close();

Report this snippet  

You need to login to post a comment.