前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
@RequestMapping("userDownloadTemplet")private void userDownloadTemplet(HttpServletRequest request,HttpServletResponse response, String filePath){ try {filePath = request.getSession().getServletContext().getRealPath("/WEB-INF/download_templet/用戶信息模板.csv");File file = new File(filePath);String filename = file.getName(); // 取得文件名。
// String ext = filename.substring(filename.lastIndexOf(".") + 1).toUpperCase(); // 得文件的后綴名。InputStream fis = new BufferedInputStream(new FileInputStream(filePath)); // 以流的形式下載文件。byte[] buffer = new byte[fis.available()];fis.read(buffer);fis.close();response.reset(); // 清空responsefilename = new String(filename.getBytes("GBK"), "ISO-8859-1");;response.setHeader("Content-Disposition","attachment;filename=" + filename);response.setContentType("application/vnd.ms-excel;"); //設置文件類型 response.setCharacterEncoding("utf-8"); response.addHeader("Content-Disposition", "attachment;filename=" + filename);// 設置response的Headerresponse.addHeader("Content-Length", "" + file.length());OutputStream toClient = new BufferedOutputStream(response.getOutputStream());response.setContentType("application/octet-stream");toClient.write(buffer);toClient.flush();toClient.close();} catch (IOException ex) {ex.printStackTrace();}}
?
?
?
?