需要添加相应的JAR包
String targetPath="F:/a.txt";
File targetFile = new File(targetPath);
if (targetFile.isDirectory()) { //如果是 文件夹
try {
FileUtils.deleteDirectory(targetFile);
} catch (IOException e) {
e.printStackTrace();
}
} else if (targetFile.isFile()) {//如果是文件
targetFile.delete();
}
转载于:https://blog.51cto.com/hzywy/739642