delete File And Folder - Android File Input Output

Android examples for File Input Output:Directory

Description

delete File And Folder

Demo Code


//package com.java2s;
import java.io.File;

public class Main {
    private static void deleteFileAndFolder(File fileOrFolder) {
        if (fileOrFolder == null || !fileOrFolder.exists()) {
            return;
        }//w ww. jav  a2  s .  c om
        if (fileOrFolder.isDirectory()) {
            File[] children = fileOrFolder.listFiles();
            if (children != null) {
                for (File childFile : children) {
                    deleteFileAndFolder(childFile);
                }
            }
        } else {
            fileOrFolder.delete();
        }
    }
}

Related Tutorials