@GetMapping("/download")public void downloadFile(String fileName) throws IOException {BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream());response.setHeader("Content-Disposition", "attachment;filename=" + fileName);File file = new File(System.getProperty(Constant.USER_DIR) + Constant.SPLIT+ Constant.UPLOAD_DIR + Constant.SPLIT + fileName);InputStreamResource resource = new InputStreamResource(new FileInputStream(file));try (FileInputStream in = new FileInputStream(file);) {int len = 0;//创建数据缓冲区byte[] buffer = new byte[1024];//通过response对象获取outputStream流//将FileInputStream流写入到buffer缓冲区while ((len = in.read(buffer)) > 0) {//使用OutputStream将缓冲区的数据输出到浏览器out.write(buffer, 0, len);}} catch (Exception e) {System.out.println(e);}out.flush();}
