Send File to Browser using JSP

Taken from Send Files to Browser Clients the Right Way:

<%
  // fetch the file
  String filename = "companySecret.txt";
  String filepath = "C:\\";
 
  response.setContentType("application/octet-stream");
  response.setHeader("Content-Disposition",
                     "attachment; filename=\"" + filename + '"');
 
  java.io.FileInputStream fileInputStream =
                     new java.io.FileInputStream(filepath + filename);
 
  int i;
  while ((i=fileInputStream.read()) != -1) {
    out.write(i);
  }
 
  fileInputStream.close();
  out.close();
%>