Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Files.move REPLACE_EXISTING cannot be resolved to a variable

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

like image 364
phil294 Avatar asked Jan 02 '15 23:01

phil294


2 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

like image 189
fge Avatar answered Sep 23 '22 03:09

fge


import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
.......
like image 35
Reimeus Avatar answered Sep 19 '22 03:09

Reimeus