The documentation of Files.move(Path source, Path target, CopyOption... options)
says:
Alternatively, suppose we want to move a file to new directory, keeping the same file name, and replacing any existing file of that name in the directory:
Path source = ... Path newdir = ... Files.move(source, newdir.resolve(source.getFileName()), REPLACE_EXISTING);
Why do I get an error in the following code then?
Files.move(Paths.get("outputFilePath"), Paths.get("inputFilePath"), REPLACE_EXISTING);
REPLACE_EXISTING cannot be resolved to a variable
You have to either write:
StandardCopyOption.REPLACE_EXISTING
or:
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
Note that you may also try and StandardCopyOption.ATOMIC_MOVE
if you can
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
.......
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With