Java Folder Copy nio copyFolder(File src, File dst, FilenameFilter filter)

Here you can find the source of copyFolder(File src, File dst, FilenameFilter filter)

Description

copy Folder

License

Apache License

Declaration

public static void copyFolder(File src, File dst, FilenameFilter filter) throws IOException 

Method Source Code

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

import java.io.File;

import java.io.FilenameFilter;
import java.io.IOException;

import java.nio.file.Files;

import java.nio.file.StandardCopyOption;

public class Main {
    public static void copyFolder(File src, File dst, FilenameFilter filter) throws IOException {
        if (src.isDirectory()) {
            if (!dst.exists()) {
                dst.mkdir();/* w ww. ja  va2  s .co  m*/
            }

            String files[] = src.list(filter);

            for (String file : files) {
                File srcFile = new File(src, file);
                File destFile = new File(dst, file);
                copyFolder(srcFile, destFile);
            }

        } else {
            copyFile(src, dst);
        }
    }

    public static void copyFolder(File src, File dst) throws IOException {
        if (src.isDirectory()) {
            if (!dst.exists()) {
                dst.mkdir();
            }

            String files[] = src.list();

            for (String file : files) {
                File srcFile = new File(src, file);
                File destFile = new File(dst, file);
                copyFolder(srcFile, destFile);
            }

        } else {
            copyFile(src, dst);
        }
    }

    public static void copyFile(File src, File dst) throws IOException {

        Files.copy(src.toPath(), dst.toPath(), StandardCopyOption.REPLACE_EXISTING);
    }
}

Related

  1. copyFolder(File sourceFolder, File destinationFolder)
  2. copyFolder(File sourceFolder, File destinationFolder)
  3. copyFolder(File sourceFolder, File destinationFolder, List blacklist)
  4. copyFolder(File src, File dest)
  5. copyFolder(File src, File dest)
  6. copyFolder(final File from, final File to)
  7. copyFolder(String path, String resultPath)
  8. copyFolderNio(String oldpathall, String newpath)
  9. copyFolders(File sourceFolder, File destFolder)