java删除文件,并删除文件夹下指定文件

水深无声 2022-08-04 15:52 462阅读 0赞
  1. public static boolean deleteFile(File file) {
  2. if(file.isDirectory()) {
  3. String[] childrenFiles = file.list();
  4. for(int i = 0; i < childrenFiles.length; i++) {
  5. boolean success = deleteFile(new File(file,childrenFiles[i]));
  6. if(!success) {
  7. return false;
  8. }
  9. }
  10. }
  11. return file.delete();
  12. }

发表评论

表情:
评论列表 (有 0 条评论,462人围观)

还没有评论,来说两句吧...

相关阅读