mirror of
https://github.com/201206030/novel-plus.git
synced 2025-07-04 16:26:40 +00:00
上传后台管理系统代码
This commit is contained in:
@ -0,0 +1,37 @@
|
||||
package com.java2nb.common.utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FileUtil {
|
||||
|
||||
public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception {
|
||||
File targetFile = new File(filePath);
|
||||
if (!targetFile.exists()) {
|
||||
targetFile.mkdirs();
|
||||
}
|
||||
FileOutputStream out = new FileOutputStream(filePath + fileName);
|
||||
out.write(file);
|
||||
out.flush();
|
||||
out.close();
|
||||
}
|
||||
|
||||
public static boolean deleteFile(String fileName) {
|
||||
File file = new File(fileName);
|
||||
// 如果文件路径所对应的文件存在,并且是一个文件,则直接删除
|
||||
if (file.exists() && file.isFile()) {
|
||||
if (file.delete()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static String renameToUUID(String fileName) {
|
||||
return UUID.randomUUID() + "." + fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user