1.前台
//文件下载按钮 function btn_download(path, file) { window.open("/Biz/LogInfo/download?path=" + path + "&file=" + file, '_blank'); }
2.日志文件下载
从服务器下载文件到浏览器
/** * 文件下载 * * @throws Exception */ @RequestMapping(value = "/download", method = {RequestMethod.GET}) public void download(HttpServletRequest request, HttpServletResponse response, String path, String file) { try { //文件位置 String downloadFile = ConstUtils.logPath + path + "/" + file; response.setContentType("application/octet-stream"); response.setHeader("Content-disposition", "attachment;filename=" + path + file); OutputStream ouputStream = response.getOutputStream(); //将文件转成byte数组 InputStream fis = new BufferedInputStream(new FileInputStream(downloadFile)); byte[] buffer = new byte[fis.available()]; fis.read(buffer); fis.close(); //文件的输出流,将数组输出到浏览器 ouputStream.write(buffer); ouputStream.flush(); ouputStream.close(); } catch (Exception e) { e.printStackTrace(); } }