delete File, return true if successful - Android java.io

Android examples for java.io:File Delete

Description

delete File, return true if successful

Demo Code

import java.io.File;

public class Main {

  public static boolean deleteFile(File file) {

    try {//from w  ww.  j  a  v  a2 s  . c  o  m
      if (file == null) {
        return true;
      }
      if (file.isDirectory()) {
        File[] files = file.listFiles();
        for (int i = 0; i < files.length; i++) {
          deleteFile(files[i]);
        }
      } else {
        file.delete();
      }

    } catch (Exception e) {
      e.printStackTrace();
      return false;
    }
    return true;
  }

}

Related Tutorials