feat:增加自动创建路径
This commit is contained in:
40
src/main/java/com/dpkj/modules/print/utils/FolderUtils.java
Normal file
40
src/main/java/com/dpkj/modules/print/utils/FolderUtils.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.dpkj.modules.print.utils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* 文件夹处理
|
||||
*
|
||||
* @author <a href="https://gitee.com/shi-chongli">石头人</a>
|
||||
* @version 1.0
|
||||
* @since 2025-03-31 17:28:34
|
||||
*/
|
||||
@Slf4j
|
||||
public class FolderUtils {
|
||||
|
||||
public static void checkFolderAndCreate(String folderPath){
|
||||
File fileOrFolder = new File(folderPath);
|
||||
String targetPath;
|
||||
if (fileOrFolder.isFile()) {
|
||||
// 如果是文件,获取文件所在目录路径
|
||||
targetPath = fileOrFolder.getParent();
|
||||
} else {
|
||||
// 如果不是文件(可能是不存在的文件夹或已存在的文件夹),使用原始路径
|
||||
targetPath = folderPath;
|
||||
}
|
||||
|
||||
File targetFolder = new File(targetPath);
|
||||
if (!targetFolder.exists()) {
|
||||
boolean success = targetFolder.mkdirs();
|
||||
if (success) {
|
||||
log.info("文件夹创建成功: " + targetPath);
|
||||
} else {
|
||||
log.error("文件夹创建失败: " + targetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user