delete Directory - Android File Input Output

Android examples for File Input Output:Directory

Description

delete Directory

Demo Code


import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Environment;

public class Main{
    static public boolean deleteDirectory(File path) {
        if (path.exists()) {
            File[] files = path.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    deleteDirectory(files[i]);
                } else {
                    files[i].delete();/*  w ww  .  j  a  va  2s  .  c  o m*/
                }
            }
        }
        return (path.delete());
    }
    static public void delete(ArrayList<String> s) {
        for (String t : s) {
            DirectoryUtils.delete(t);
        }
    }
    static public boolean delete(String s) {
        File f = new File(s);

        if (f == null || !f.exists()) {
            return false;
        }
        if (f.isDirectory()) {
            return deleteDirectory(f);
        }
        return f.delete();
    }
}

Related Tutorials