JAVA中用递归函数来删除子目录

import java.io.File;

  以下是递归函数内容:

   private Boolean pDeleteDirectory(String filePath) {

          Boolean bTotalRlt = true;

          File file = new File(filePath);

          File[] fileList = file.listFiles();

          String dirPath = null;

          if (fileList != null) {

              for (int i = 0; i < fileList.length; i++) {

                  if (fileList[i].isFile()) {

                      bTotalRlt = bTotalRlt && fileList[i].delete();

                  }

                  if (fileList[i].isDirectory()) {

                      dirPath = fileList[i].getPath();

                      bTotalRlt = bTotalRlt && pDeleteDirectory(dirPath);

                  }

              }

              bTotalRlt = bTotalRlt && file.delete();

          }

          return bTotalRlt;

      }

你可能感兴趣的:(JAVA中用递归函数来删除子目录)