-
@param source source path must not be null
-
@param target target path must not be null
*/
public static void copyFolder(@NonNull Path source, @NonNull Path target) throws IOException {
Assert.notNull(source, “Source path must not be null”);
Assert.notNull(target, “Target path must not be null”);
Files.walkFileTree(source, new SimpleFileVisitor
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
throws IOException {
Path current = target.resolve(source.relativize(dir).toString());
Files.createDirectories(current);
return FileVisitResult.CONTINUE;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
throws IOException {
Files.copy(file, target.resolve(source.relativize(file).toString()),
StandardCopyOption.REPLACE_EXISTING);
return FileVisitResult.CONTINUE;
}
});
}
/**
-
Deletes folder recursively.
-
@param deletingPath deleting path must not be null
*/
public static void deleteFolder(@NonNull Path deletingPath) throws IOException {
Assert.notNull(deletingPath, “Deleting path must not be null”);
if (Files.notExists(deletingPath)) {
return;
}
log.info(“Deleting [{}]”, deletingPath);
delete(deletingPath.toFile());
log.info(“Deleted [{}] successfully”, deletingPath);
}
public static void delete(File file) {
if(file.isDirectory()){
Arrays.asList(file.listFiles()).forEach(e->{
delete(e);
});
}
file.delete();
}
/**
-
Renames file or folder.
-
@param pathToRename file path to rename must not be null
-
@param newName new name must not be null
*/
public static void rename(@NonNull Path pathToRename, @NonNull String newName)
throws IOException {
Assert.notNull(pathToRename, “File path to rename must not be null”);
Assert.notNull(newName, “New name must not be null”);
Path newPath = pathToRename.resolveSibling(newName);
log.info(“Rename [{}] to [{}]”, pathToRename, newPath);
Files.move(pathToRename, newPath);
log.info(“Rename [{}] successfully”, pathToRename);
}
/**
-
Unzips content to the target path.
-
@param zis zip input stream must not be null
-
@param targetPath target path must not be null and not empty
-
@throws IOException throws when failed to access file to be unzipped
*/
public static void unzip(@NonNull ZipInputStream zis, @NonNull Path targetPath)
throws IOException {
// 1. unzip file to folder
// 2. return the folder path
Assert.notNull(zis, “Zip input stream must not be null”);
Assert.notNull(targetPath, “Target path must not be null”);
// Create path if absent
createIfAbsent(targetPath);
// Folder must be empty
ensureEmpty(targetPath);
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
// Resolve the entry path
Path entryPath = targetPath.resolve(zipEntry.getName());
// Check directory
checkDirectoryTraversal(targetPath, entryPath);
if (zipEntry.isDirectory()) {
// Create directories
Files.createDirectories(entryPath);
} else {
// Copy file
Files.copy(zis, entryPath);
}
zipEntry = zis.getNextEntry();
}
}
/**
-
Unzips content to the target path.
-
@param bytes zip bytes array must not be null
-
@param targetPath target path must not be null and not empty
-
@throws IOException io exception
*/
public static void unzip(@NonNull byte[] bytes, @NonNull Path targetPath) throws IOException {
Assert.notNull(bytes, “Zip bytes must not be null”);
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(bytes));
unzip(zis, targetPath);
}
/**
-
Zips folder or file.
-
@param pathToZip file path to zip must not be null
-
@param pathOfArchive zip file path to archive must not be null
-
@throws IOException throws when failed to access file to be zipped
*/
public static void zip(@NonNull Path pathToZip, @NonNull Path pathOfArchive)
throws IOException {
try (OutputStream outputStream = Files.newOutputStream(pathOfArchive)) {
try (ZipOutputStream zipOut = new ZipOutputStream(outputStream)) {
zip(pathToZip, zipOut);
}
}
}
/**
-
Zips folder or file.
-
@param pathToZip file path to zip must not be null
-
@param zipOut zip output stream must not be null
-
@throws IOException throws when failed to access file to be zipped
*/
public static void zip(@NonNull Path pathToZip, @NonNull ZipOutputStream zipOut)
throws IOException {
// Zip file
zip(pathToZip, pathToZip.getFileName().toString(), zipOut);
}
/**
小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数初中级Java工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!
因此收集整理了一份《2024年最新Java开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Java)
最后希望可以帮助到大家!
千千万万要记得:多刷题!!多刷题!!
之前算法是我的硬伤,后面硬啃了好长一段时间才补回来,算法才是程序员的灵魂!!!!
篇幅有限,以下只能截图分享部分的资源!!
(1)多线程(这里以多线程为代表,其实整理了一本JAVA核心架构笔记集)
(2)刷的算法题(还有左神的算法笔记)
(3)面经+真题解析+对应的相关笔记(很全面)
(4)视频学习(部分)
ps:当你觉得学不进或者累了的时候,视频是个不错的选择
在这里,最后只一句话:祝大家offer拿到手软!!
法是我的硬伤,后面硬啃了好长一段时间才补回来,算法才是程序员的灵魂!!!!
篇幅有限,以下只能截图分享部分的资源!!
(1)多线程(这里以多线程为代表,其实整理了一本JAVA核心架构笔记集)
[外链图片转存中…(img-JRWBm6tC-1711133160106)]
(2)刷的算法题(还有左神的算法笔记)
[外链图片转存中…(img-L9JtEoy5-1711133160107)]
(3)面经+真题解析+对应的相关笔记(很全面)
[外链图片转存中…(img-ckVhHA6c-1711133160107)]
(4)视频学习(部分)
ps:当你觉得学不进或者累了的时候,视频是个不错的选择
在这里,最后只一句话:祝大家offer拿到手软!!