0

I am trying to move a file from a folder A: "/files/attachments/2000/filename.txt" to folder B: "/files/attachments/trashbin/2000/filename.txt" but I keep getting the exception: FileAlreadyExistsException and the exception output is: "/files/attachments/trashbin/2000".

this is the code:

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(...){}

Can anyone suggest why it is happening? this is the documentation: 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...)

Yahav
  • 146
  • 11
  • Can you print `filePath` and `trashBinPath.resolve(fileName)`? The exception seems to say that the destination file is not what you think. – assylias May 18 '20 at 06:36
  • trashBinPath.resolve(fileName): /files/attachments/trashbin/2000/filename.txt filePath: /files/attachments/2000/filename.txt trashBinPath: /files/attachments/trashbin/2000 – Yahav May 18 '20 at 08:31

1 Answers1

0

Experienced the same thing, this part was the issue when comparing your code to mine after fixing the issue.

"/files/attachments/trashbin/2000".

it needs to be

"/files/attachments/trashbin/2000/".