package com.example.nettytest.nio.day2;
import java.io.IOException;
import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @description:
* @author: xz
* @create: 2022-07-31 11:08
*/
public class TestWalkFileTree {
public static void main(String[] args) throws IOException {
copyMoreDirectory();
}
/**
* 拷贝多级目录
* */
private static void copyMoreDirectory() throws IOException {
long start = System.currentTimeMillis();
String source = "E:\\apache-tomcat-8.5.78-副本";
String target = "E:\\apache-tomcat-8.5.78-副本-666";
//拷贝多级目录
Files.walk(Paths.get(source)).forEach(path -> {
//原路径替换成一个新的路径
String targetName = path.toString().replace(source, target);
//如果是目录
if(Files.isDirectory(path)){
try {
Files.createDirectory(Paths.get(targetName));
} catch (IOException e) {
e.printStackTrace();
}
}
//如果是普通文件
if(Files.isRegularFile(path)){
//拷贝
try {
Files.copy(path, Paths.get(targetName));
} catch (IOException e) {
e.printStackTrace();
}
}
});
long end = System.currentTimeMillis();
System.out.println("计算出拷贝文件的时间差===="+(end - start));
}
}
版权说明 : 本文为转载文章, 版权归原作者所有 版权申明
原文链接 : https://wwwxz.blog.csdn.net/article/details/126092318
内容来源于网络,如有侵权,请联系作者删除!