java - Files.write(Path,byte[]) 上的 java.nio.channels.ClosedByInterruptException
问题描述
我需要下载附件文件(例如 jpeg、gif、pdf 等)我使用了 Files.write(Path,byte[]) 方法,但我得到了 ClosedByInterruptException
public String downloadattachment(){
try {
headers.set("authorization", authorization);
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<byte[]> result =
restTemplate.exchange(attachmentUrl,
HttpMethod.GET, entity, byte[].class);
String fileName =
result.getHeaders().getContentDisposition().getFilename();
String pathDirStr = applicationProperties.getLoggerPath() +
File.separator + ticketId;
SyncUtils.createDirIfNotExist(pathDirStr);
String pathFile = pathDirStr+File.separator+fileName;
Files.write(Paths.get(pathFile), result.getBody());
logger.debug("Attachment file downloaded in location : " +
pathFile);
resultPath=pathFile;
} catch (Exception e) {
logger.debug("Exception occur while downloading attachment file.", e);
} return resultPath;
}
痕迹:
"java.nio.channels.ClosedByInterruptException: null
at java.nio.channels.spi.AbstractInterruptibleChannel.end(Unknown Source)
at sun.nio.ch.FileChannelImpl.write(Unknown Source)
at java.nio.channels.Channels.writeFullyImpl(Unknown Source)
at java.nio.channels.Channels.writeFully(Unknown Source)
at java.nio.channels.Channels.access$000(Unknown Source)
at java.nio.channels.Channels$1.write(Unknown Source)
at java.nio.file.Files.write(Unknown Source)
at com.rogers.service.ComcastServiceImpl.downloadComcastAttachmentInDir(ComcastServiceImpl.java:564)
解决方案
推荐阅读
- r - 给定单词模式匹配R的条件字符串格式
- model-view-controller - 如何从数据库中获取选定的值并在 dropdwon 中显示值 - Codeigniter 3
- python - 未知类属性的文档字符串样式?
- vuejs2 - 我想使用时刻显示我放入数组中的日期
- git - 如何通过 Visual Studio Code 中的命令面板(Ctrl+Shift+P)删除远程 Git 分支?
- jquery - 对象未添加到 Mongodb 集合中,有时
- spring - Spring @GetMapping 不适用于子资源
- ios - 同类型的UIGestureRecognizer如何指定优先级?
- java - 每次使用嵌套循环打印字符串时如何取出字符串的最后一个字符
- php - Tiktalik API,Laravel,获取请求,邮递员