The StandardCopyOption enumeration implements the CopyOption interface and defines the types of copy operation supported.
Value | Meaning |
---|---|
ATOMIC_MOVE | The move operation is atomic in nature |
COPY_ATTRIBUTES | The source file attributes are copied to the new file |
REPLACE_EXISTING | The destination file is replaced if it exists |
import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; public class Main { public static void main(String[] args) throws Exception { Path sourceFile = Paths.get("C:/home/docs/users.txt"); Path destinationFile = Paths.get("C:/home/music/users.txt"); Files.move(sourceFile, destinationFile); Files.move(sourceFile, destinationFile, StandardCopyOption.ATOMIC_MOVE); }// w ww . j av a 2 s . c o m }