Springboot 删除指定文件夹或文件(Java删除指定文件夹或文件)
Springboot 删除指定文件夹或文件(Java删除指定文件夹或文件)
·
代码如下:
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));
}
}
更多推荐
已为社区贡献5条内容
所有评论(0)