Springboot 删除指定文件夹或文件

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)