|
时 间 记 忆 |
<< < 2018 - 3 > >>
日 |
一 |
二 |
三 |
四 |
五 |
六 |
|
|
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
|
|
|
|
|
|
java 文件下载 |
[ 2017-3-12 21:21:00 | By: 我家超超会发光 ] |
/** * 报表下载 * * @param response * @param wb * @param excelName */ public static void downloadFile(HttpServletResponse response, HSSFWorkbook wb, String excelName) throws Exception { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String nowDate = df.format(new Date()); String fileName = excelName + nowDate + ".xls"; response.setContentType("application/octet-stream; charset=UTF-8"); response.addHeader("Content-Disposition", "attachment; filename=\"" + new String(fileName.trim()) + "\""); OutputStream out = response.getOutputStream(); wb.write(out); out.flush(); out.close(); }
/** * 报表下载 * * @param response * @param wb * @param excelName */ public static void downloadFile2007(HttpServletResponse response, ***FWorkbook wb, String excelName) throws Exception { SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss"); String nowDate = df.format(new Date()); String fileName = excelName + nowDate + ".xlsx"; response.setContentType("application/octet-stream; charset=UTF-8"); fileName = URLEncoder.encode(fileName, "UTF-8"); response.setHeader("Content-Disposition", "attachment; filename=" + fileName); OutputStream out = response.getOutputStream(); wb.write(out); out.flush(); out.close(); }
public static void downloadFile(String path, HttpServletResponse response) throws FileNotFoundException { try { // path 是指欲下载的文件路径 File file = new File(path); // 获取文件名 String fileName = file.getName(); // 获取文件的后缀名 InputStream fis = new BufferedInputStream(new FileInputStream(path)); OutputStream toClient = new BufferedOutputStream(response.getOutputStream()); // 设置输出的格式 response.setContentType("application/octet-stream; charset=UTF-8"); response.addHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\""); int len; byte[] buffer = new byte[1024 * 10]; while ((len = fis.read(buffer)) != -1) { toClient.write(buffer, 0, len); } toClient.flush(); toClient.close(); fis.read(); fis.close(); } catch (IOException e) { e.printStackTrace(); } } |
|
|
|
|