@RequestMapping(value = "/oldDateExcleDown", method = RequestMethod.GET)
public void oldDateExcleDown(HttpServletRequest request, HttpServletResponse response) throws IOException {
FileInputStream fileInputStream = null;
ServletOutputStream outputStream = null;
String contentType = "application/vnd.ms-excel";
response.setContentType(contentType);
response.setCharacterEncoding("UTF-8");
try {
outputStream = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment; filename=\"" + URLEncoder.encode( "excelExport" + ".xls", "UTF-8") + "\"");
String roomNoUrl = this.getClass().getResource("/templates/oldProofInfo.xlsx").getPath();
fileInputStream = new FileInputStream(new File(roomNoUrl));
int len = 0;
byte[] bytes = new byte[1024];
while ((len = fileInputStream.read(bytes)) != -1){
outputStream.write(bytes,0,len);
outputStream.flush();
}
} catch (IOException e) {
throw e;
} finally {
//关闭资源
outputStream.close();
fileInputStream.close();
}
}
05-26
491
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
04-17
636
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交