直接上代碼

           //定義文件路徑
            String filePath = "/upload/img/1.jpg";
            //這里因為我文件是相對路徑 所以需要在路徑前面加一個點
            File file = new File("."+filePath);
            if (file.exists()){//文件是否存在
                file.delete();//刪除文件
            }
            //從數(shù)據庫刪除文件
            userFileService.deleteById(file_id);
            //剩下的 從硬盤刪除 后面再寫
            result.setMsg("刪除成功");
            result.setCode(1);