Java 多级目录的文件夹拷贝
Java 大约 859 字代码
public class FilesCopyDemo {
public static void main(String[] args) throws IOException {
String source = "D:/abc";
String target = "D:/abc123";
Path sourcePath = Paths.get(source);
Path targetPath = Paths.get(target);
Files.walk(sourcePath).forEach(path -> {
try {
String targetName = path.toString().replace(sourcePath.toString(), targetPath.toString());
System.out.println("targetName#" + targetName);
if (Files.isDirectory(path)) {
Files.createDirectory(Paths.get(targetName));
} else if (Files.isRegularFile(path)) {
Files.copy(path, Paths.get(targetName));
}
} catch (IOException e) {
e.printStackTrace();
}
});
}
}
阅读 396 · 发布于 2021-12-08
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Kubernetes 数据存储 NFS阅读 231
-
MySQL update limit 更新限定条数阅读 2531
-
Nginx 编译安装时提示 the HTTP gzip module requires the zlib library阅读 5613
-
Prometheus+Grafana+nginx-lua-prometheus 监控 OpenResty阅读 941
-
Java 并发的基石 LockSupport阅读 855
-
Linux tac 倒序查看文本内容阅读 2191
-
Windows 平台 lua-resty-upload 上传的文件无法打开阅读 1219
-
面试题:二进制与十进制互相转换阅读 1962
-
k3s 部署简化版 Kubernetes阅读 312
-
Android ContentLoadingProgressBar 进度条控件阅读 6018