|
|
|
@ -131,22 +131,27 @@ public class AppFileUtils {
|
|
|
|
|
* 根据旧路径删除图片
|
|
|
|
|
* @param oldPath 图片路径
|
|
|
|
|
*/
|
|
|
|
|
public static void removeFileByPath(String oldPath) {
|
|
|
|
|
// 图片的路径不是默认图片的路径
|
|
|
|
|
if (!oldPath.endsWith(Constast.DEFAULT_IMG_GOODS) && !oldPath.endsWith(Constast.DEFAULT_IMG_USER)) {
|
|
|
|
|
public static boolean removeFileByPath(String oldPath) {
|
|
|
|
|
// 图片的路径是默认用户头像则不执行删除操作
|
|
|
|
|
if (oldPath != null && oldPath.endsWith(Constast.DEFAULT_IMG_USER)) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
assert oldPath != null;
|
|
|
|
|
File file = new File(UPLOAD_PATH, oldPath);
|
|
|
|
|
// 文件存在则删除
|
|
|
|
|
if (file.exists()) {
|
|
|
|
|
if (!file.delete()) {
|
|
|
|
|
|
|
|
|
|
// 文件删除失败,抛出异常
|
|
|
|
|
if (file.delete()) {
|
|
|
|
|
return true;
|
|
|
|
|
} else {
|
|
|
|
|
throw new RuntimeException("文件删除失败: " + file.getAbsolutePath());
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 文件不存在,抛出异常
|
|
|
|
|
throw new RuntimeException("文件不存在: " + file.getAbsolutePath());
|
|
|
|
|
// 文件不存在
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|