java - Files.move 不断在目录上抛出文件已存在异常
问题描述
我正在尝试将文件从文件夹 A:“/files/attachments/2000/filename.txt”移动到文件夹 B:“/files/attachments/trashbin/2000/filename.txt”,但我不断收到异常:FileAlreadyExistsException异常输出是:“/files/attachments/trashbin/2000”。
这是代码:
Path filePath = Paths.get(pathOnNFS.concat(folderPath).concat(Utils.DELIMITER + fileName));
Path trashBinPath = Paths.get(trashBinNFS.concat(folderPath));
try {
Files.createDirectories(trashBinPath);
Files.move(filePath, trashBinPath.resolve(fileName), StandardCopyOption.REPLACE_EXISTING);
}catch(...){}
任何人都可以提出为什么会这样吗?这是文档:https ://docs.oracle.com/en/java/javase/12/docs/api/java.base/java/nio/file/Files.html#move(java.nio.file.Path ,java.nio.file.Path,java.nio.file.CopyOption...)
解决方案
推荐阅读
- c# - 如何在 Prism 中不打开 MainWindow 的情况下创建模块目录和 Reigster 类型
- python - Pandas:agg() 给我的“系列”对象是可变的,因此它们不能被散列
- android - 完成后获取多个网络请求的结果
- python - 有没有办法加快在 python 中处理大型 CSV 和数据帧?
- php - Office365 smtp 并不总是与 php 邮件程序一起使用
- node.js - Typescript 编译的 JS 可以工作,但 ts-node-dev 抛出编译错误
- python - General setter for a class using strings
- mysql - 验证另一个表中记录的记录数据
- python - 当 __hash__ 和 __eq__ 在没有参数的情况下不可调用时,Python 的 dict 如何将类型管理为键?
- python - 使用 matplotlib 的热图的等距方向