Copying a directory using Files.copy() method - Java File Path IO

Java examples for File Path IO:Directory Copy

Description

Copying a directory using Files.copy() method

Demo Code

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

public class Main {
  public static void main(String[] args) {
    Path originalDirectory = FileSystems.getDefault().getPath("C:/home/docs");
    Path newDirectory = FileSystems.getDefault().getPath("C:/home/tmp");
    try {/* w  ww .  j ava  2s . com*/
      Files.copy(originalDirectory, newDirectory);
      System.out.println("Directory copied successfully!");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Related Tutorials