新需求开发
This commit is contained in:
parent
bdce485bb0
commit
e25839b045
|
|
@ -122,6 +122,7 @@ public class FileUploadController {
|
|||
@PostMapping("singleUploadFile")
|
||||
public Result singleUploadFile(@RequestParam(value = "file", required = false) MultipartFile file){
|
||||
try {
|
||||
fileISexit(uploadPath);
|
||||
FileExportVo files=new FileExportVo();
|
||||
// 获取文件名
|
||||
String fileName = StringUtils.cleanPath(Objects.requireNonNull(file.getOriginalFilename()));
|
||||
|
|
@ -148,6 +149,7 @@ public class FileUploadController {
|
|||
@PostMapping("mostUploadFile")
|
||||
public Result mostUploadFile(@RequestParam(value = "files", required = false) MultipartFile[] data){
|
||||
try {
|
||||
fileISexit2(uploadPath);
|
||||
List<MultipartFile> multipartFiles = Arrays.asList(data);
|
||||
List<FileExportVo> list=new ArrayList<>();
|
||||
for (MultipartFile multipartFile:multipartFiles){
|
||||
|
|
@ -219,4 +221,42 @@ public class FileUploadController {
|
|||
return Result.fail();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void fileISexit(String path){
|
||||
File directory = new File(path);
|
||||
// 检查目录是否存在,不存在则创建
|
||||
if (!directory.exists()) {
|
||||
// 尝试创建多层目录
|
||||
boolean isCreated = directory.mkdirs();
|
||||
if (isCreated) {
|
||||
System.out.println("目录已成功创建!");
|
||||
} else {
|
||||
System.out.println("目录创建失败!");
|
||||
}
|
||||
} else {
|
||||
System.out.println("目录已存在。");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void fileISexit2(String path){
|
||||
File file = new File(path+"file.txt");
|
||||
// 检查文件是否存在,不存在则创建
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
// 尝试创建新文件
|
||||
boolean isCreated = file.createNewFile();
|
||||
if (isCreated) {
|
||||
System.out.println("文件已成功创建!");
|
||||
} else {
|
||||
System.out.println("文件创建失败!");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println("创建文件时发生错误:" + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
System.out.println("文件已存在。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue