Files.move(Path source, Path target, CopyOption... options)
的文档说:
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);
为什么我会在下面的代码中出错?
Files.move(Paths.get("outputFilePath"), Paths.get("inputFilePath"), REPLACE_EXISTING);
REPLACE_EXISTING cannot be resolved to a variable
最佳答案
你必须写:
StandardCopyOption.REPLACE_EXISTING
或:
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
请注意,如果可以的话,您也可以尝试 StandardCopyOption.ATOMIC_MOVE
关于java - Files.move REPLACE_EXISTING 无法解析为变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27749755/