Files.move REPLACE_EXISTING cannot be resolved by a variable

The documentation Files.move(Path source, Path target, CopyOption... options)says:

As an alternative, suppose we want to move the file to a new directory, keeping the same file name and replacing any existing file with this name in the directory:

 Path source = ...
 Path newdir = ...
 Files.move(source, newdir.resolve(source.getFileName()), REPLACE_EXISTING);

Why am I getting an error in the following code?

 Files.move(Paths.get("outputFilePath"), Paths.get("inputFilePath"), REPLACE_EXISTING);

REPLACE_EXISTING cannot be resolved by variable

+4
source share
3 answers

You need to either write:

StandardCopyOption.REPLACE_EXISTING

or

import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;

Please note that you can also try and StandardCopyOption.ATOMIC_MOVEif you can

+10
source
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
.......
+2
source

java.nio.file.CopyOption, (), , , : java.nio.file.StandardCopyOption, StandardCopyOption.REPLACE_EXISTING

0

Source: https://habr.com/ru/post/1569781/


All Articles