递归删除指定文件夹下所有文件

    技术2025-04-27  23

    /** * 删除文件夹,包括文件夹下所有文件 <功能详细描述> * * @param path 文件夹路径 */ public void deleteFile(String path) { File pathFile = new File(path); if (!pathFile.exists()) { return; } else { if (pathFile.isDirectory()) { String[] tempPaths = pathFile.list(); for (String tempPath : tempPaths) { deleteFile(path + File.separator + tempPath); } } boolean status = pathFile.delete(); System.out.println("delete: "+ path); if (!status) { System.out.println("deleting file error"); } } } 

    最新回复(0)