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

intcopyDirectory(File srcFile, File destFile)
copy Directory
if (!srcFile.isDirectory())
    return SRC_NOT_DIRECTORY;
if (destFile.exists() && !destFile.isDirectory())
    return DEST_EXISTS_NOT_DIR;
if (destFile.exists()) {
    if (destFile.list().length > 0)
        return DEST_EXISTS_NON_EMPTY;
} else {
...
voidcopyDirectory(File srcPath, File dstPath)
copy Directory
if (srcPath.isDirectory()) {
    if (!dstPath.exists()) {
        dstPath.mkdirs();
    String files[] = srcPath.list();
    for (int i = 0; i < files.length; i++) {
        copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
} else {
    if (srcPath.exists()) {
        InputStream in = new FileInputStream(srcPath);
        OutputStream out = new FileOutputStream(dstPath);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        in.close();
        out.close();
voidcopyDirectory(File srcPath, File dstPath)
Copy directory.
if (srcPath.isDirectory()) {
    if (!dstPath.exists()) {
        dstPath.mkdirs();
    String files[] = srcPath.list();
    for (int i = 0; i < files.length; i++) {
        copyDirectory(new File(srcPath, files[i]), new File(dstPath, files[i]));
} else {
    InputStream in = null;
    OutputStream out = null;
    try {
        in = new FileInputStream(srcPath);
        out = new FileOutputStream(dstPath);
        transfer(in, out);
    } finally {
        if (in != null) {
            in.close();
        if (out != null) {
            out.flush();
            out.close();
voidcopyDirectory(final File sourceDir, final File destDir)
copy Directory
if (!destDir.exists()) {
    destDir.mkdir();
File[] children = sourceDir.listFiles();
for (File sourceChild : children) {
    String name = sourceChild.getName();
    File destChild = new File(destDir, name);
    if (sourceChild.isDirectory()) {
...
voidcopyDirectory(final File src, final File dest)
copy Directory
String[] files = src.list();
for (String f : files) {
    File current = new File(src, f);
    if (current.isDirectory()) {
        copyDirectory(current, new File(dest, f));
    } else {
        copyFile(current, new File(dest, f));
voidcopyDirectory(final String sourceDir, final String targetDir)
Copy a directory
new File(targetDir).mkdirs();
final File[] file = new File(sourceDir).listFiles();
for (int i = 0; i < file.length; i++) {
    if (file[i].isFile()) {
        final File sourceFile = file[i];
        final File targetFile = new File(
                new File(targetDir).getAbsolutePath() + File.separator + file[i].getName());
        copyFile(sourceFile, targetFile);
...
voidcopyDirectory(String sourceDir, String targetDir)
copy Directory
File sourceFolder = new File(sourceDir);
if (sourceFolder.exists()) {
    File targetFolder = new File(targetDir);
    if (!targetFolder.exists()) {
        targetFolder.mkdirs();
    File[] files = sourceFolder.listFiles();
    for (int i = 0; i < files.length; i++) {
...
voidcopyDirectory(String srcDir, String destDir)
copy Directory
try {
    File dDir = new File(destDir);
    File sDir = new File(srcDir);
    dDir.mkdirs();
    File[] file = sDir.listFiles();
    int flength = file.length;
    for (int i = 0; i < flength; i++) {
        if (file[i].isFile() && !file[i].getName().endsWith(".dll")) {
...
voidcopyDirectoryAndOverwriteFilesIfNeeded(File srcDir, File destDir)
Method similar to FileUtils.copyDirectory, but with overwrite
if (srcDir == null || destDir == null) {
    throw new IllegalArgumentException("Null inputs");
if (!srcDir.exists()) {
    throw new IllegalArgumentException("Source folder does not exist: " + srcDir.getAbsolutePath());
recursiveCopy(srcDir, destDir);
booleancopyDirectoryContent(File srcPath, File targetPath)
Copy existing directory on srcPath into non-existing targetPath directory.
if (srcPath.isDirectory()) {
    targetPath.mkdirs();
    File[] srcChildFiles = srcPath.listFiles();
    boolean ok = true;
    for (int i = 0; i < srcChildFiles.length; i++) {
        File srcFile = srcChildFiles[i];
        boolean temp = copyDirectoryContent(srcFile, new File(targetPath, srcFile.getName()));
        if (!temp) {
...