java-删除某目录下所有文件

 1 private boolean delZSPic(String filePath) {
 2     boolean flag = true;
 3     if(filePath != null) {
 4         File file = new File(filePath);
 5         if(file.exists()) {
 6             File[] filePaths = file.listFiles();
 7             for(File f : filePaths) {
 8                 if(f.isFile()) {
 9                     f.delete();
10                 }
11                 if(f.isDirectory()){
12                     String fpath = f.getPath();
13                     delZSPic(fpath);
14                     f.delete();
15                 }
16             }
17         }
18     }else {
19         flag = false;
20     }
21     return flag;
22 }

猜你喜欢

转载自www.cnblogs.com/lujiannt/p/9214316.html