@RequestMapping(path = "/download")
public String download(String id, HttpServletResponse response) {
response.setCharacterEncoding("utf-8");
OutputStream os=null;
InputStream inputStream = null;
try {
UploadFileForRunFlowProcess file = fileForRunFlowProcOrderService.get(id);
response.setHeader("Content-Disposition", "attachment;fileName="
+ new String(file.getOriginalName().getBytes("UTF-8"),"iso-8859-1"));
response.addHeader("Content-Length", "" + file.getSize());
response.setContentType("application/octet-stream;charset=UTF-8");
String path = fileForRunFlowProcOrderService.getAbsoluteRootPath() + file.getUrl().substring(7);
inputStream = new FileInputStream(path);
os = response.getOutputStream();
byte[] b = new byte[2048];
int length;
while ((length = inputStream.read(b)) > 0) {
java实现文件下载的三种方式
最新推荐文章于 2023-11-04 19:36:15 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)