通过设置response
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition","attachment; filename=\""
+ fileName + ".xls" +"\"");
然后response.write()直接写文件的内容
另外大文件写入response的时候,推荐这么使用:
out.write(xmlForExcel.toString().getBytes());out.flush();out.close();
xmlForExcel.delete(0, xmlForExcel.length());
byte b[] = new byte[5000];
FileInputStream in = new FileInputStream(file);
int n=0;
while((n=in.read(b))!=-1){
tempOut.write(new String(b,0,n));
}
可以防止内存溢出