| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下载文件工具(提示选择路径) |
| | | * |
| | | * @param downfile |
| | | * 导出的文件 |
| | | * @param fileName |
| | | * 导出的文件名称 |
| | | */ |
| | | public static void DownFileTips( HttpServletResponse response, File downfile, String fileName) { |
| | | try { |
| | | if(StringUtils.isEmpty(fileName)){ |
| | | fileName = downfile.getName(); |
| | | } |
| | | String filename = ""; |
| | | filename = URLEncoder.encode(fileName,"UTF8");//其他浏览器 |
| | | InputStream fis = new BufferedInputStream(new FileInputStream( |
| | | downfile)); |
| | | byte[] buffer = new byte[fis.available()]; |
| | | fis.read(buffer); |
| | | fis.close(); |
| | | |
| | | response.addHeader("Content-Disposition", "attachment;filename="+ filename); |
| | | OutputStream toClient= new BufferedOutputStream(response.getOutputStream()); |
| | | response.setContentType("application/vnd.ms-excel;charset=utf-8"); |
| | | |
| | | toClient.write(buffer); |
| | | toClient.flush(); |
| | | toClient.close(); |
| | | } catch (FileNotFoundException e) { |
| | | e.printStackTrace(); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | } |