problem with download file from JSP
843838May 9 2007 — edited May 15 2007Below is my code in servlet, it works, the problem is my excel file has contents within it, it is not an empty file, but when the program download the excel file to local, it becomes an empty file rather than the original one, would anyone help me for this?
File fFile = new File(c:\\TEST\test.xls);
String stFileName = "test.xls";
response.setContentType("application/excel");
response.setHeader("Content-Disposition", "attachment;filename=\""
+ stFileName + "\"");
InputStream isStream = null;
ServletOutputStream sosStream = null;
try {
isStream = new FileInputStream(fFile);
sosStream = response.getOutputStream();
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = isStream.read(buff, 0, buff.length))) {
sosStream.write(buff, 0, bytesRead);
}
sosStream.flush();
sosStream.close();
isStream.close();
}
catch (IOException ioeException) {
ioeException.printStackTrace();
}