I'm creating every time a file moving and replacing it from source folder to a destination folder with the same name in a loop and this is the problem :
For the first move and replace, it works well then it yells the process cannot access the file because it is being used by another process. when replacing the file in the destination folder and this is the method moving the file and replacing it every time
public static void moveAndReplaceFile(String source, String destination) {
try {
Files.move(
Paths.get(source),
Paths.get(destination),
StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
LOGGER.error("Fail when moving and replacing");
}
}
can you help me guys? thanks in advance