Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with download file from JSP

843838May 9 2007 — edited May 15 2007
Below 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();
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 12 2007
Added on May 9 2007
7 comments
264 views