Java Utililty Methods Directory Copy

List of utility methods to do Directory Copy

Description

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

Method

voidcopyDirectory(File file, File folderDestino)
copy Directory
if (file != null && file.exists()) {
    File newFile = new File(folderDestino.getAbsolutePath() + File.separator + file.getName());
    if (file.isDirectory()) {
        newFile.mkdir();
        for (File f : file.listFiles()) {
            copyDirectory(f, newFile);
    } else {
...
booleancopyDirectory(File from, File to)
Copy a directory and all of its contents.
return copyDirectory(from, to, (byte[]) null);
voidcopyDirectory(File inDir, File outDir)
copy Directory
if (!inDir.isDirectory()) {
    return;
for (File f : inDir.listFiles()) {
    File outFile = new File(outDir, f.getName());
    if (f.isDirectory()) {
        outFile.mkdirs();
        copyDirectory(f, outFile);
...
booleancopyDirectory(File inDir, File outDir)
Copy a complete directory tree from one directory to another.
outDir.mkdirs();
File[] files = inDir.listFiles();
for (File inFile : files) {
    File outFile = new File(outDir, inFile.getName());
    if (inFile.isFile()) {
        if (!copy(inFile, outFile))
            return false;
    } else {
...
voidcopyDirectory(File inputFolder, File outputFolder)
copy Directory
outputFolder.getParentFile().mkdirs();
for (File innerFile : inputFolder.listFiles()) {
    if (innerFile.isDirectory()) {
        copyDirectory(innerFile, new File(outputFolder.getCanonicalPath() + "/" + innerFile.getName()));
    if (innerFile.isFile()) {
        copyFile(innerFile, new File(outputFolder.getCanonicalPath() + "/" + innerFile.getName()));
voidcopyDirectory(File source, File destination)
This is a recursive directory copy function.
if (source.isDirectory()) {
    if (!destination.exists()) {
        destination.mkdir();
    String[] contents = source.list();
    for (int i = 0; i < contents.length; i++) {
        copyDirectory(new File(source, contents[i]), new File(destination, contents[i]));
} else {
    if (destination.isDirectory()) {
        copyFile(source, new File(destination, source.getName()));
    } else {
        copyFile(source, destination);
voidcopyDirectory(File source, File destination)
Copy a directory from source to target including its contained files and directories.
destination.mkdirs();
if (!source.exists()) {
    return;
for (File file : source.listFiles()) {
    if (file.isDirectory()) {
        copyDirectory(file, new File(destination.getAbsolutePath() + File.separatorChar + file.getName()));
    } else {
...
voidcopyDirectory(File source, File destination)
copy Directory
copyDirectory(source, destination, null);
booleancopyDirectory(File source, File destination)
Copying recursively a directory to another.
boolean result = true;
if (!source.exists()) {
    return false;
if ((destination.mkdirs() == false) && (!destination.isDirectory())) {
    return false;
File[] files = source.listFiles();
...
voidcopyDirectory(File source, File destination, boolean overwrite)
copy Directory
Assert.isLegal(source != null);
Assert.isLegal(source.isDirectory());
Assert.isLegal(destination != null);
destination = getDestinationDirectory(source, destination);
if (!destination.exists()) {
    destination.mkdir();
for (File content : source.listFiles()) {
...