Java Path Copy nio copyRecursive(Path source, Path target, CopyOption... options)

Here you can find the source of copyRecursive(Path source, Path target, CopyOption... options)

Description

copy Recursive

License

Open Source License

Declaration

public static void copyRecursive(Path source, Path target, CopyOption... options) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;

public class Main {
    public static void copyRecursive(Path source, Path target, CopyOption... options) throws IOException {
        Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
            @Override/*from   ww  w  . j  a v  a2  s  .c  o m*/
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                Files.createDirectories(target.resolve(source.relativize(dir)));
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                Files.copy(file, target.resolve(source.relativize(file)), options);
                return FileVisitResult.CONTINUE;
            }
        });
    }
}

Related

  1. copyFiles(String urlDir, String outPath)
  2. copyFilesAndApplyPermissions(Path sourceDir, Path targetDir, List filenames)
  3. copyFilesRecursively(final Path from, final Path to)
  4. copyFileToArchive(InputStream srcInputStream, Path destPath)
  5. copyFileToDataFolder(ClassLoader cl, String resourceName, Path targetFolder, boolean replace)
  6. copyRecursively(File fromDirectory, File toDirectory)
  7. copyRecursively(File src, File dest)
  8. copyRecursively(File src, File dest)
  9. copyRecursively(final Path source, final Path destination, final CopyOption... options)