Java Files move file

Description

Java Files move file

import java.io.IOException;
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) {
    Path source = Paths.get("C:/Data/Main.java");
    Path target = Paths.get("C:/myData/dir2/Main.java");

    try {//w ww  . j  a v  a 2 s  . c  om
      Path p = Files.move(source, target, StandardCopyOption.ATOMIC_MOVE);
      System.out.println(source + " has been moved to " + p);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}



PreviousNext

Related