delete Folder Contents recursively - Android java.io

Android examples for java.io:File Delete

Description

delete Folder Contents recursively

Demo Code

import java.io.File;

public class Main {

  public static boolean deleteContents(File dir) {
    File[] files = dir.listFiles();
    boolean success = true;
    if (files != null) {
      for (File file : files) {
        if (file.isDirectory()) {
          success &= deleteContents(file);
        }/*from ww w .  ja  v a 2  s. com*/
        if (!file.delete()) {
          success = false;
        }
      }
    }
    return success;
  }

}

Related Tutorials