浏览代码

代码优化

xujunwei 6 月之前
父节点
当前提交
3985054910
共有 1 个文件被更改,包括 25 次插入0 次删除
  1. 25 0
      framework-common/src/main/java/com/mrxu/framework/common/util/FileFunc.java

+ 25 - 0
framework-common/src/main/java/com/mrxu/framework/common/util/FileFunc.java

@@ -302,5 +302,30 @@ public class FileFunc {
 		}
 	}
 
+	/**
+	 * 确保路径存在
+	 * @param path
+	 */
+	@SneakyThrows
+	public static void surePathExists(String path) {
+		// 目标文件夹路径
+		Path dirPath = Paths.get(path);
+		// 检查目录是否存在,如果不存在则创建
+		if (!Files.exists(dirPath)) {
+			Files.createDirectories(dirPath);
+		}
+	}
+
+	/**
+	 * 删除文件
+	 * @param path
+	 */
+	public static void deleteFile(String path) {
+		File file = new File(path);
+		if(file.exists()) {
+			file.delete();
+		}
+	}
+
 
 }