Java Files copy directory

Description

Java Files copy directory

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 {//from   w  w w  .  jav a 2s  .  c om
         Files.copy(originalDirectory, newDirectory);
         System.out.println("Directory copied successfully!");
      } catch (IOException e) {
         e.printStackTrace();
      }

   }

}



PreviousNext

Related