代码如下:

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删除文件

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐