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); 1REPLACE_EXISTING cannot be resolved to a variable
3 Answers
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; ....... The documentation says its an argument of interface type java.nio.file.CopyOption, which has this implementation (an enum) that you're probably looking for: java.nio.file.StandardCopyOption which has a definition for StandardCopyOption.REPLACE_EXISTING