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

voidcopyDirectoryContents(File directory, String targetDirName, boolean update)
Copies the contents of a directory to the specified target directory.
copyDirectoryContents(directory, new File(targetDirName), update);
voidcopyDirectoryContents(File source, File destination)
Recursively copies the contents of the source directory into the destination directory.
File[] fileList = source.listFiles();
if (fileList != null) {
    for (int i = 0; i < fileList.length; i++) {
        if (fileList[i].isDirectory()) {
            File newDir = new File(destination, fileList[i].getName());
            newDir.mkdir();
            copyDirectoryContents(fileList[i], newDir);
        } else if (fileList[i].getName().equals(".DS_Store")) {
...
booleancopyDirectoryContents(File src, File target)
copy Directory Contents
Preconditions.checkArgument(src.isDirectory(), "Source dir is not a directory: %s", src);
if (isSymbolicLink(src)) {
    return false;
target.mkdirs();
Preconditions.checkArgument(target.isDirectory(), "Target dir is not a directory: %s", src);
boolean success = true;
for (File file : listFiles(src)) {
...
voidcopyDirectoryContents(File srcDir, File dstDir)
copy Directory Contents
File[] listFiles = srcDir.listFiles();
if (listFiles != null) {
    for (File srcFile : listFiles) {
        if (srcFile.isDirectory()) {
            copyDirectory(srcFile, new File(dstDir, srcFile.getName()));
        } else {
            copy(srcFile, new File(dstDir, srcFile.getName()));
voidcopyDirectoryFromJar(String jarName, String srcDir, File tmpDir)
copy Directory From Jar
JarFile jf = null;
JarInputStream jarInputStream = null;
try {
    jf = new JarFile(jarName);
    JarEntry je = jf.getJarEntry(srcDir);
    if (je.isDirectory()) {
        FileInputStream fis = new FileInputStream(jarName);
        BufferedInputStream bis = new BufferedInputStream(fis);
...
voidcopyDirectoryTree(File copyFrom, File copyTo)
copy Directory Tree
if (copyFrom.isDirectory()) {
    copyTo.mkdirs();
    String fileList[] = copyFrom.list();
    for (int i = 0; i < fileList.length; i++) {
        File targetFile = new File(copyTo, fileList[i]);
        File sourceFile = new File(copyFrom, fileList[i]);
        copyDirectoryTree(sourceFile, targetFile);
} else {
    FileInputStream inputStream = new FileInputStream(copyFrom);
    FileOutputStream outputStream = new FileOutputStream(copyTo);
    int chararcterToCopy;
    while ((chararcterToCopy = inputStream.read()) >= 0)
        outputStream.write(chararcterToCopy);
    inputStream.close();
    outputStream.close();
voidcopyDirectoryWithContents(final File srcPath, final File dstPath)
This methods copies a directory with all its files.
if (srcPath.isDirectory()) {
    if (!dstPath.exists()) {
        dstPath.mkdir();
    final String[] files = srcPath.list();
    if (files.length > 0) {
        Arrays.sort(files);
        for (int index = 0; index < files.length; index++) {
...