package com.learning.files;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class FilesCopy {
public static void main(String[] args) throws IOException {
String source = "E:\\study";
String target = "E:\\studycopy";
Files.walk(Paths.get(source)).forEach(path -> {
try {
String targetName = path.toString().replace(source, target);
if (Files.isDirectory(path)) {
Files.createDirectory(Paths.get(targetName));
}
else if(Files.isRegularFile(path)){
Files.copy(path, Paths.get(targetName));
}
}catch(Exception e){
e.printStackTrace();
}
});
}
}