Here you can find the source of copyFilesRecursively(final Path from, final Path to)
public static void copyFilesRecursively(final Path from, final Path to) throws IOException
//package com.java2s; /*//w w w . j a v a 2s.com * Copyright (C) 2016 Google Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import com.google.common.base.Preconditions; import java.io.IOException; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.SimpleFileVisitor; import java.nio.file.StandardCopyOption; import java.nio.file.attribute.BasicFileAttributes; public class Main { /** * Copies files from {@code from} directory to {@code to} directory. If any file exist in the * destination it fails instead of overwriting. * * <p>File attributes are also copied. * * <p>Symlinks are kept as in the origin. If a symlink points to "../foo" it will point to * that "../foo" in the destination. If it points to "/usr/bin/foo" it will point to * "/usr/bin/foo" */ public static void copyFilesRecursively(final Path from, final Path to) throws IOException { Preconditions.checkArgument(Files.isDirectory(from), "%s (from) is not a directory"); Preconditions.checkArgument(Files.isDirectory(to), "%s (to) is not a directory"); Files.walkFileTree(from, new SimpleFileVisitor<Path>() { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { Path destFile = to.resolve(from.relativize(file)); Files.createDirectories(destFile.getParent()); if (Files.isSymbolicLink(file)) { Path realDestination = Files.readSymbolicLink(file); Files.createSymbolicLink(destFile, realDestination); return FileVisitResult.CONTINUE; } Files.copy(file, destFile, StandardCopyOption.COPY_ATTRIBUTES); return FileVisitResult.CONTINUE; } }); } }