/** * @Description 下载文件 * @author zhangyd * @date 2015年12月11日 下午6:11:33 * @param fileName * @param file * @return * @throws IOException */ public ResponseEntity download(String fileName, File file) throws IOException { String dfileName = new String(fileName.getBytes("gb2312"), "iso8859-1"); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); headers.setContentDispositionFormData("attachment", dfileName); return new ResponseEntity(FileUtils.readFileToByteArray(file), headers, HttpStatus.CREATED); }
作者: 慕冬雪
链接:http://www.imooc.com/article/2760
来源:慕课网
springmvc文件下载简洁代码
最新推荐文章于 2023-04-05 20:24:19 发布