文件下载 @Log("文件下载") @RequestMapping(value = "download", method = RequestMethod.GET) public String download(HttpServletResponse response) { String fileName = "1.jpg"; String basePath = "c://data/"; String filePath = basePath+fileName; response.setHeader("content-type", "application/octet-stream"); response.setContentType("application/octet-stream"); response.setHeader("Content-Disposition", "attachment;filename=" + fileName); byte[] bytes = new byte[1024]; BufferedInputStream bis = null; OutputStream os = null; try { os = response.getOutputStream(); bis = new BufferedInputStream(new FileInputStream(new File(filePath))); int i = bis.read(bytes); while (i != -1) { os.write(bytes, 0, bytes.length); os.flush(); i = bis.read(bytes); } } catch (IOException e) { e.printStackTrace(); } finally { if (bis != null) { try { bis.close(); return "success"; } catch (IOException e) { e.printStackTrace(); return "false"; } } } return null; }
springboot-文件下载
最新推荐文章于 2024-06-27 11:00:34 发布