Saturday, March 14, 2009

Send File to Browser using JSP

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();

No comments: