response.setHeader("Content-Disposition", "attachment;filename="
+ java.net.URLEncoder.encode(name+".xlsx", "UTF-8"));
// FileInputStream fis = new FileInputStream(path); fis.available()==file.length()
response.addHeader("Content-Length", "" + file.length());
response.setContentType("application/octet-stream");
OutputStream out = response.getOutputStream();
//一次性读
//fileinputstream fis = new fileinputsteam(new File(xxx));
//byte[] b = new byte[fis.available]
//out.write(b)
//循环读
byte[] b = new byte[1024];
int len = 0;
while((len = fis.read(b))!=-1){
out.write(b, 0, len);
}
out.flush();
out.close();
fis.close();