phi*_*294 5 java replace file move
文件Files.move(Path source, Path target, CopyOption... options)
说:
或者,假设我们要将文件移动到新目录,保留相同的文件名,并替换目录中该名称的任何现有文件:
Run Code Online (Sandbox Code Playgroud)Path source = ... Path newdir = ... Files.move(source, newdir.resolve(source.getFileName()), REPLACE_EXISTING);
为什么我在以下代码中出现错误呢?
Files.move(Paths.get("outputFilePath"), Paths.get("inputFilePath"), REPLACE_EXISTING);
Run Code Online (Sandbox Code Playgroud)
REPLACE_EXISTING无法解析为变量
fge*_*fge 14
你必须写:
StandardCopyOption.REPLACE_EXISTING
Run Code Online (Sandbox Code Playgroud)
要么:
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
Run Code Online (Sandbox Code Playgroud)
请注意,您也可以尝试,StandardCopyOption.ATOMIC_MOVE
如果可以的话