代码如下:
package com.example.controller;
import org.springframework.util.FileSystemUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.File;
@RestController
public class FileController {
/**
* 删除指定文件夹或文件
* @param path 文件夹或文件路径
* @return Boolean 删除成功返回true,删除失败返回false。
*/
@PostMapping("/file/delete/custom/path")
public Boolean uploadCustomPathFile(@RequestParam("path")String path){
return FileSystemUtils.deleteRecursively(new File(path));
}
}
参考:Springboot 删除指定文件夹或文件_码蚁1203的博客-CSDN博客_springboot删除文件