Here you can find the source of copy(Path source, Path destination)
public static void copy(Path source, Path destination) throws IOException
//package com.java2s; //License from project: Apache License import java.io.FileNotFoundException; import java.io.IOException; import java.nio.file.DirectoryStream; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.StandardCopyOption; public class Main { public static void copy(Path source, Path destination) throws IOException { if (source.equals(destination)) { return; } else if (!Files.exists(source)) { throw new FileNotFoundException("No such file/dir to copy: " + source); } else if (Files.isDirectory(source)) { if (!Files.exists(destination)) { Files.createDirectories(destination); }/*w w w. jav a 2s . c om*/ try (DirectoryStream<Path> files = Files.newDirectoryStream(source)) { for (Path file : files) { copy(file, destination.resolve(file.getFileName())); } } } else { Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING); } Files.setLastModifiedTime(destination, Files.getLastModifiedTime(source)); } }