【发布时间】:2019-10-29 11:02:21
【问题描述】:
在重命名文件后尝试移动文件时出现以下异常,问题是它间歇性发生,即有时代码有效,有时无效且不可复制,如果有人能提供有关相同的见解,将会很有帮助
Caused by: java.nio.file.AccessDeniedException: /data/Inprocess/DEMO.20191026.csv -> /data/Inprocess/DEMO.20191026.csv.inprogress
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:84)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixCopyFile.move(UnixCopyFile.java:457)
at sun.nio.fs.UnixFileSystemProvider.move(UnixFileSystemProvider.java:262)
at java.nio.file.Files.move(Files.java:1395)
Path fromPath = inputFile.toPath();
Path toPath = new File(inputFile.getAbsolutePath() + ".inprogress").toPath();
LOGGER.info("Moving file to Path: " + inputFile.getAbsolutePath() + ".inprogress");
try {
Files.move(fromPath, fromPath.resolveSibling(toPath),StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
// Handle Exception
throw new TradeProcessorException("Error while marking file Inprogress: ", e);
}
【问题讨论】: