mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
add FileSystemUtil
This commit is contained in:
parent
a5ea0ef1ed
commit
7afad66075
@ -0,0 +1,47 @@
|
|||||||
|
package cn.hutool.core.io.file;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.IORuntimeException;
|
||||||
|
import cn.hutool.core.map.MapUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileSystem;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link FileSystem}相关工具类封装<br>
|
||||||
|
* 参考:https://blog.csdn.net/j16421881/article/details/78858690
|
||||||
|
*
|
||||||
|
* @author looly
|
||||||
|
* @since 5.7.15
|
||||||
|
*/
|
||||||
|
public class FileSystemUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建 {@link FileSystem}
|
||||||
|
*
|
||||||
|
* @param path 文件路径,可以是目录或Zip文件等
|
||||||
|
* @return {@link FileSystem}
|
||||||
|
*/
|
||||||
|
public static FileSystem create(String path) {
|
||||||
|
try {
|
||||||
|
return FileSystems.newFileSystem(
|
||||||
|
Paths.get(path).toUri(),
|
||||||
|
MapUtil.of("create", "true"));
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new IORuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取目录的根路径,或Zip文件中的根路径
|
||||||
|
*
|
||||||
|
* @param fileSystem {@link FileSystem}
|
||||||
|
* @return 根 {@link Path}
|
||||||
|
*/
|
||||||
|
public static Path getRoot(FileSystem fileSystem) {
|
||||||
|
return fileSystem.getPath(StrUtil.SLASH);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user