Program to Copy a Directory - using's copyDirectory method- java file IO

Must read Directory operations - create, identify, delete, traverse.'s copyDirectory(sourceDirectory, destDirectory) method can also be used for copying Directory from source to destination.

Program to Copy a Directory - using's copyDirectory(sourceDirectory, destDirectory)- java file IO >

/** */
public class CopyDirectoryUsingCommonsJar {
   public static void main(String... args) {
          String sourceDirectoryName = "c:/myDirectory";
          File sourceDirectory = new File(sourceDirectoryName);
          String destDirectoryName = "c:/myDirectoryCopy";
          File destDirectory = new File(destDirectoryName);
          try {
                 FileUtils.copyDirectory(sourceDirectory, destDirectory);
                 System.out.println(sourceDirectoryName + " copied successfully to "
                              + destDirectoryName);
          } catch (IOException e) {
c:/myDirectory copied successfully to c:/myDirectoryCopy

Note : In order to avoid you must use's isDirectory() method to ensure that sourceDirectoryName is a directory. I haven't used it just to keep the code simple.


Program to Create Directory - Single and multiple (i.e. parent and child directories) in java file IO

Program to Identify File or Directory - in java file IO | And in java 7 using java.nio.file

Traverse a Directory (all sub-directories and files) in 2 ways

Program to Write BYTE data type in file using DataOutputStream and Read BYTE from file using DataInputStream - java file IO

Must read for you :