Java Recursive Copy recursiveCopyDir(File source, File destination)

Here you can find the source of recursiveCopyDir(File source, File destination)

Description

recursive Copy Dir

License

Apache License

Declaration

private static void recursiveCopyDir(File source, File destination) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import com.google.common.io.Files;
import java.io.*;

public class Main {
    private static void recursiveCopyDir(File source, File destination) throws IOException {
        if (source.isDirectory()) {
            if (!destination.exists()) {
                if (!destination.mkdirs()) {
                    throw new IOException("The destination directory could not be created.");
                }/*from  ww  w.  ja va  2  s .c o m*/
            }

            String files[] = source.list();

            for (String file : files) {
                File srcFile = new File(source, file);
                File destFile = new File(destination, file);
                recursiveCopyDir(srcFile, destFile);
            }
        } else {
            Files.copy(source, destination);
        }
    }
}

Related

  1. recursiveCopy(File copyFromDir, File copyToDir, boolean overwrite)
  2. recursiveCopy(File sourceFile, File targetLocation)
  3. recursiveCopy(File src, File dest)
  4. recursiveCopyFile(File srcDir, File destDir)