实名认证
This commit is contained in:
@ -0,0 +1,32 @@
|
||||
package com.ruoyi.common.tool;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Service
|
||||
public class FileDeletionService {
|
||||
/**
|
||||
* 根据文件路径删除文件
|
||||
* @param filePath 文件的完整路径
|
||||
* @return 如果文件删除成功返回 true,否则返回 false
|
||||
*/
|
||||
public boolean deleteFileByPath(String filePath) {
|
||||
if (filePath == null || filePath.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
File file = new File(filePath);
|
||||
// 检查文件是否存在并且是一个普通文件
|
||||
if (file.exists() && file.isFile()) {
|
||||
try {
|
||||
// 执行删除操作
|
||||
return file.delete();
|
||||
} catch (SecurityException e) {
|
||||
// 处理没有权限删除文件的异常
|
||||
System.err.println("没有权限删除文件: " + filePath);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user