赞
踩
/** * 根据文件名下载模板 * * @param response * @param fileName */ @Override public void downloadTemplate(HttpServletResponse response, String fileName) { OutputStream os = null; InputStream is = null; try { InputStream inputStream = this.getClass().getResourceAsStream("/template/" + fileName); File somethingFile = File.createTempFile("template", ".xlsx"); try { FileUtils.copyInputStreamToFile(inputStream, somethingFile); } finally { inputStream.close(); } InputStream in = new FileInputStream(somethingFile); // 取得输出流 os = response.getOutputStream(); response.setContentType("application/vnd.ms-excel"); response.setHeader("Content-Disposition", "attachment;filename=1.xlsx"); //复制 IOUtils.copy(in, response.getOutputStream()); response.getOutputStream().flush(); } catch (IOException e) { System.out.println("下载文件失败," + e.getMessage()); } finally { try { if (is != null) { is.close(); } } catch (IOException e) { } try { if (os != null) { os.close(); } } catch (IOException e) { } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。