Java Utililty Methods Copy Directory

List of utility methods to do Copy Directory

Description

The list of methods to do Copy Directory are organized into topic(s).

Method

voidcopyDirectory(File src, File dest)
Copies a directory to another location recursively
if (src.isDirectory()) {
    File destFile = new File(dest.getAbsolutePath() + "/" + src.getName());
    if (!destFile.exists()) {
        if (!destFile.mkdirs()) {
            throw new Exception("Could not Create " + destFile.getAbsolutePath());
    for (File srcFile : src.listFiles()) {
...
voidcopyDirectory(File src, File dest, boolean force)
copy Directory
if (!src.exists())
    throw new IOException("Source directory does not exist: " + src);
if (src.isDirectory()) {
    if (!dest.exists()) {
        if (!dest.mkdir())
            throw new IOException("Unable to create directory: " + dest);
    for (String file : src.list()) {
...
voidcopyDirectory(File src, File dst)
Copy a directory and its contents.
if (src.isDirectory()) {
    if (!dst.exists()) {
        dst.mkdirs();
    for (String child : src.list()) {
        copyDirectory(new File(src, child), new File(dst, child));
} else {
...
voidcopyDirectory(File srcDir, File destDir)
copy Directory
File[] srcFiles = srcDir.listFiles();
if (srcFiles == null) {
    throw new IOException("Failed to list contents of " + srcDir);
if (destDir.exists()) {
    if (!(destDir.isDirectory())) {
        throw new IOException("Destination '" + destDir + "' exists but is not a directory");
} else if ((!(destDir.mkdirs())) && (!(destDir.isDirectory()))) {
    throw new IOException("Destination '" + destDir + "' directory cannot be created");
if (!(destDir.canWrite())) {
    throw new IOException("Destination '" + destDir + "' cannot be written to");
for (File srcFile : srcFiles) {
    File dstFile = new File(destDir, srcFile.getName());
    if (srcFile.isDirectory())
        copyDirectory(srcFile, dstFile);
    else {
        copyFile(srcFile, dstFile);
voidcopyDirectory(File srcDir, File dstDir)
copy Directory
if (srcDir.isDirectory()) {
    if (!dstDir.exists()) {
        dstDir.mkdir();
    String[] children = srcDir.list();
    for (int i = 0; i < children.length; i++) {
        copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
} else {
    copyFile(srcDir, dstDir);
voidcopyDirectory(File srcDir, File dstDir)
Copies all files under srcDir to dstDir.
if (srcDir.isDirectory()) {
    if (!dstDir.exists()) {
        if (!dstDir.mkdirs()) {
            throw new IOException("Failed to create directory " + dstDir.getAbsolutePath());
    String[] children = srcDir.list();
    if (children != null) {
...
voidcopyDirectory(File srcDir, File dstDir)
copy Directory
if (srcDir.isDirectory()) {
    if (!dstDir.exists()) {
        dstDir.mkdir();
    String[] children = srcDir.list();
    for (int i = 0; i < children.length; i++) {
        copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
} else {
    copyFile(srcDir, dstDir);
voidcopyDirectory(File srcDir, File dstDir)
Copies source directory to destination directory.
if (srcDir.isDirectory()) {
    if (!dstDir.exists()) {
        dstDir.mkdir();
    String[] children = srcDir.list();
    for (int i = 0; i < children.length; i++) {
        copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
} else {
    copyFile(srcDir, dstDir);
voidcopyDirectory(File srcDir, File dstDir)
copy Directory
if (srcDir.isDirectory()) {
    if (!dstDir.exists()) {
        dstDir.mkdirs();
    String[] children = srcDir.list();
    for (int i = 0; i < children.length; i++) {
        copyDirectory(new File(srcDir, children[i]), new File(dstDir, children[i]));
} else {
    copy(srcDir, dstDir);
voidcopyDirectory(File srcDir, File dstDir)
copy Directory
if (".svn".equals(srcDir.getName())) {
    return;
if (srcDir.isDirectory()) {
    if (!dstDir.exists()) {
        dstDir.mkdir();
    for (String aChildren : srcDir.list()) {
...