记录下excel文件导出到客户端下载的方法,其他文件也是一样
OutputStream out = response.getOutputStream();
File file = new File(path);
InputStream fis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[fis.available()];
ffis.read(buffer);
ffis.close();
response.reset();
response.setContentType("text/html;charset=UTF-8");
OutputStream toClient = new BufferedOutputStream(out);
response.setContentType("application/x-msdownload");
String newName = URLEncoder.encode(id, "UTF-8");;
response.addHeader("Content-Disposition", "attachment;filename=\"" + newName + "\"");
response.addHeader("Content-Length", "" + file.length());
toClient.write(buffer);
toClient.flush();
file.deleteOnExit();