Paste_Image.png
public String downTemplate(HttpServletRequest request, HttpServletResponse response) throws IOException {
File f = ResourceUtils.getFile("classpath:template/导出成绩.xls");
try {
response.setCharacterEncoding("UTF-8");
String fileName = new String("导出成绩.xls".getBytes("UTF-8"),
"ISO8859-1");
fileName = fileName.replaceAll("\\+", "%20");
response.setHeader("Cache-control", "private");
response.setHeader("Cache-Control", "maxage=3600");
response.setHeader("Pragma", "public");
response.setContentType("application/vnd.ms-excel");
response.setContentType("application/octet-stream;charset=UTF-8;");
response.setHeader("Accept-Ranges", "bytes");
response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\"");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
ServletOutputStream out = response.getOutputStream();
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(f));
bos = new BufferedOutputStream(out);
byte[] buff = new byte[2048];
int bytesRead;
while (-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff, 0, bytesRead);
}
} catch (final IOException e) {
throw e;
} finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
return null;
}
网友评论