MCPcopy Create free account
hub / github.com/SeanDragon/protools / ToolFile

Class ToolFile

common/src/main/java/pro/tools/file/ToolFile.java:21–1543  ·  view source on GitHub ↗

文件相关工具 @author SeanDragon

Source from the content-addressed store, hash-verified

19 * @author SeanDragon
20 */
21public final class ToolFile {
22
23 private ToolFile() {
24 throw new UnsupportedOperationException("我是工具类,别初始化我。。。");
25 }
26
27 /**
28 * 根据文件路径获取文件
29 *
30 * @param filePath
31 * 文件路径
32 *
33 * @return 文件
34 */
35 public static File getFileByPath(String filePath) {
36 return ToolStr.isSpace(filePath) ? null : new File(filePath);
37 }
38
39 /**
40 * 判断文件是否存在
41 *
42 * @param filePath
43 * 文件路径
44 *
45 * @return {@code true}: 存在<br>{@code false}: 不存在
46 */
47 public static boolean isFileExists(String filePath) {
48 return isFileExists(getFileByPath(filePath));
49 }
50
51 /**
52 * 判断文件是否存在
53 *
54 * @param file
55 * 文件
56 *
57 * @return {@code true}: 存在<br>{@code false}: 不存在
58 */
59 public static boolean isFileExists(File file) {
60 return file != null && file.exists();
61 }
62
63 /**
64 * 重命名文件
65 *
66 * @param filePath
67 * 文件路径
68 * @param newName
69 * 新名称
70 *
71 * @return {@code true}: 重命名成功<br>{@code false}: 重命名失败
72 */
73 public static boolean rename(String filePath, String newName) {
74 return rename(getFileByPath(filePath), newName);
75 }
76
77 /**
78 * 重命名文件

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected