Java Files.move(Path source, Path target, CopyOption ... options)

Syntax

Files.move(Path source, Path target, CopyOption ... options) has the following syntax.

public static Path move(Path source,  Path target,  CopyOption ... options)   throws IOException

Example

In the following code shows how to use Files.move(Path source, Path target, CopyOption ... options) method.


//ww  w .j av a 2s .c  o  m

import java.io.IOException;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;


public class Main {

    public static void main(String[] args) {

        Path movefrom = FileSystems.getDefault().getPath("C:/tutorial/Swing_2.jpg");
        Path target = FileSystems.getDefault().getPath("C:/tutorial/photos/Swing_2.jpg");
        Path target_dir = FileSystems.getDefault().getPath("C:/tutorial/photos");

        //method 1
        try {
            Files.move(movefrom, target, StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            System.err.println(e);
        }


    }
}




















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService