Browse Source

图片同步完成

xujunwei 6 months atrás
parent
commit
3dcccf7367

+ 11 - 3
framework-common/src/main/java/com/mrxu/framework/common/util/FileFunc.java

@@ -264,7 +264,8 @@ public class FileFunc {
 		Path rootPath = Paths.get(pathStr);
 		Map<String, String> fileMap = new HashMap<>();
 		if (!Files.exists(rootPath)) {
-			throw new BusinessException("指定的路径不存在: " + pathStr);
+			return fileMap;
+			// throw new BusinessException("指定的路径不存在: " + pathStr);
 		}
 		if (!Files.isDirectory(rootPath)) {
 			throw new BusinessException("指定的路径不是一个文件夹: " + pathStr);
@@ -286,8 +287,15 @@ public class FileFunc {
 		return fileMap;
 	}
 
-	public static void newFile(String path, String content) {
-		try (BufferedWriter writer = new BufferedWriter(new FileWriter(path))) {
+	@SneakyThrows
+	public static void newFile(String path,String fileName, String content) {
+		// 目标文件夹路径
+		Path dirPath = Paths.get(path);
+		// 检查目录是否存在,如果不存在则创建
+		if (!Files.exists(dirPath)) {
+			Files.createDirectories(dirPath);
+		}
+		try (BufferedWriter writer = new BufferedWriter(new FileWriter(path+"/"+fileName))) {
 			writer.write(content);
 		} catch (IOException e) {
 			throw new BusinessException("文件写入异常"+e.getMessage());