在java
中我们除了用这种方式删除文件:
File file = new File("D:\file\projects\img-comparison-demo\target\generated-sources");
if (file.exists()) {
try {
boolean delete = file.delete();
} catch (Exception e) {
e.printStackTrace();
}
}
还可以使用Files
工具类:
try {
boolean delete = Files.deleteIfExists(Paths.get("D:\file\projects\img-comparison-demo\target\generated-sources"));
} catch (IOException e) {
e.printStackTrace();
}
Files
还提供了很多的api
就不一一列举了,大家自行探索吧