Package cool.scx.common.util
Class FileUtils
java.lang.Object
cool.scx.common.util.FileUtils
文件 操作类
- Version:
- 0.0.1
- Author:
- scx567888
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcopy(Path source, Path target, CopyOption... options) 本质上就是调用Files.copy(Path, Path, CopyOption...),但是在之前会创建不存在的父目录static voidstatic void删除文件或文件夹static longdisplaySizeToLong(String str) 将 格式化后的大小转换为 long 如将 1KB 转换为 1024static StringgetExtension(String path) 获取拓展名 (不包括 . ) 例 : "cat.png" 会获得 "png"static StringgetFileName(String path) 获取文件名static String获取文件名 (不包括拓展名 ) 例 : "cat.png" 会获得 "cat"static byte[]static StringgetHeadAsHex(String filePath, int length) static StringlongToDisplaySize(long size) 将 long 类型的文件大小 格式化(转换为人类可以看懂的形式) 如 1024 转换为 1KBstatic voidstatic voidmove(Path source, Path target, CopyOption... options) 本质上就是调用Files.move(Path, Path, CopyOption...),但是在之前会创建不存在的父目录static voidwrite(Path path, byte[] bytes, OpenOption... options) 本质上就是调用Files.write(Path, byte[], OpenOption...),但是在之前会创建不存在的父目录
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
delete
删除文件或文件夹- Parameters:
start- 起始目录excludeRoot- 实现清空文件夹的效果 排除根目录 (删除文件为 "文件" 时无效, "目录" 时有效) 比如 未使用此选项调用 delete("/user/test") 文件夹 则 test 文件夹会被删除 若使用此选项则 会清空 test 下所有文件 test 目录则会保留- Throws:
IOException- e
-
delete
- Throws:
IOException
-
move
本质上就是调用Files.move(Path, Path, CopyOption...),但是在之前会创建不存在的父目录- Parameters:
source- atarget- aoptions- a- Throws:
IOException- a
-
copy
本质上就是调用Files.copy(Path, Path, CopyOption...),但是在之前会创建不存在的父目录- Parameters:
source- atarget- aoptions- a- Throws:
IOException- a
-
write
本质上就是调用Files.write(Path, byte[], OpenOption...),但是在之前会创建不存在的父目录- Parameters:
path- abytes- aoptions- a- Throws:
IOException- a
-
getHeadAsHex
- Throws:
IOException
-
getHead
- Throws:
IOException
-
getFileName
获取文件名- Parameters:
path- a- Returns:
- a
-
getExtension
获取拓展名 (不包括 . ) 例 : "cat.png" 会获得 "png" -
getFileNameWithoutExtension
获取文件名 (不包括拓展名 ) 例 : "cat.png" 会获得 "cat" -
longToDisplaySize
将 long 类型的文件大小 格式化(转换为人类可以看懂的形式) 如 1024 转换为 1KB- Parameters:
size- a long.- Returns:
- a
Stringobject.
-
displaySizeToLong
将 格式化后的大小转换为 long 如将 1KB 转换为 1024- Parameters:
str- 待转换的值 如 5MB 13.6GB- Returns:
- a long.
-
merge
- Throws:
IOException
-