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 }

 

posted @ 2018-06-22 16:55  派小星  阅读(4124)  评论(0编辑  收藏  举报