处理文件流关闭问题
This commit is contained in:
+10
-11
@@ -43,25 +43,24 @@ public class SplitFileController {
|
|||||||
splitIndex = fileUrl.lastIndexOf("/");
|
splitIndex = fileUrl.lastIndexOf("/");
|
||||||
}
|
}
|
||||||
String fileName = fileUrl.substring(splitIndex + 1);
|
String fileName = fileUrl.substring(splitIndex + 1);
|
||||||
|
// response.setHeader("Content-Disposition",
|
||||||
|
// "attachment; filename=\""+fileName+"\"");
|
||||||
response.setHeader("Content-Disposition",
|
response.setHeader("Content-Disposition",
|
||||||
"attachment; filename=\""+fileName+"\"");
|
"attachment; filename=\"" + SplitFileUtils.encodeFileName(fileName, request) + "\"");
|
||||||
response.setHeader("Content-Disposition",
|
|
||||||
"attachment; filename=\""+ SplitFileUtils.encodeFileName(fileName, request) +"\"");
|
|
||||||
response.setContentType("application/force-download");
|
response.setContentType("application/force-download");
|
||||||
try(OutputStream os = response.getOutputStream();
|
if (CosBootUtil.doesObjectExist(fileUrl)) {
|
||||||
/*FileInputStream fis = new FileInputStream(fileUrl);*/) {
|
try (OutputStream os = response.getOutputStream();
|
||||||
if (CosBootUtil.doesObjectExist(fileUrl)) {
|
InputStream fis = CosBootUtil.download(fileUrl)) {
|
||||||
InputStream fis = CosBootUtil.download(fileUrl);
|
|
||||||
int len = 0;
|
int len = 0;
|
||||||
while ((len = fis.read()) != -1) {
|
while ((len = fis.read()) != -1) {
|
||||||
os.write(len);
|
os.write(len);
|
||||||
}
|
}
|
||||||
os.flush();
|
os.flush();
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new JeroBootException("文件不存在");
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new JeroBootException("文件不存在");
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
throw new JeroBootException("文件不存在");
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new JeroBootException("文件不存在");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user