Android Utililty Methods Directory Clean

List of utility methods to do Directory Clean

Description

The list of methods to do Directory Clean are organized into topic(s).

Method

voidcleanDirectory(File directory)
clean Directory
if (!directory.exists()) {
    String message = directory + " does not exist";
    throw new IllegalArgumentException(message);
if (!directory.isDirectory()) {
    String message = directory + " is not a directory";
    throw new IllegalArgumentException(message);
IOException exception = null;
File[] files = directory.listFiles();
for (File file : files) {
    try {
        forceDelete(file);
    } catch (IOException ioe) {
        exception = ioe;
if (null != exception) {
    throw exception;
} else {
    return;
voidcleanDirectory(File directory)
Cleans a directory without deleting it.
if (!directory.exists()) {
    String message = directory + " does not exist";
    throw new IllegalArgumentException(message);
if (!directory.isDirectory()) {
    String message = directory + " is not a directory";
    throw new IllegalArgumentException(message);
File[] files = directory.listFiles();
if (files == null) { 
    throw new IOException("Failed to list contents of " + directory);
IOException exception = null;
for (int i = 0; i < files.length; i++) {
    File file = files[i];
    try {
        forceDelete(file);
    } catch (IOException ioe) {
        exception = ioe;
if (null != exception) {
    throw exception;
voidcleanDirectory(String directory)
clean Directory
cleanDirectory(new File(directory));
voidcleanDirectory(final File directory)
Clean a directory without delete it
if (!directory.exists()) {
    final String message = directory + " does not exist";
    throw new IllegalArgumentException(message);
if (!directory.isDirectory()) {
    final String message = directory + " is not a directory";
    throw new IllegalArgumentException(message);
final File[] files = directory.listFiles();
if (files == null) { 
    throw new IOException("Failed to list content of " + directory);
IOException exception = null;
for (final File file : files) {
    try {
        forceDelete(file);
    } catch (final IOException ioe) {
        exception = ioe;
if (null != exception) {
    throw exception;
voidclearDir(String dirPath)
clear Dir
if (StringUtil.isEmpty(dirPath)) {
    return;
File file = new File(dirPath);
if (!file.exists() || file.isFile()) {
    return;
File[] files = file.listFiles();
...