Android Directory Clean clearDir(String dirPath)

Here you can find the source of clearDir(String dirPath)

Description

clear Dir

License

Apache License

Declaration

public static void clearDir(String dirPath) 

Method Source Code

//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.regex.Pattern;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Main{
    public static void clearDir(String dirPath) {
        if (StringUtil.isEmpty(dirPath)) {
            return;
        }/*from w w w .  ja v a2s.  c om*/

        File file = new File(dirPath);
        if (!file.exists() || file.isFile()) {
            return;
        }

        File[] files = file.listFiles();
        if (ArrayUtil.isEmpty(files)) {
            return;
        }
        for (File tempFile : files) {
            deleteFile(tempFile.getPath());
        }
    }
    public static void deleteFile(String filePath) {
        if (StringUtil.isEmpty(filePath)) {
            return;
        }

        File file = new File(filePath);
        if (!file.exists()) {
            return;
        }

        if (file.isDirectory()) {
            for (File tempFile : file.listFiles()) {
                deleteFile(tempFile.getPath());
            }
        }

        file.delete();
    }
}

Related

  1. cleanDirectory(File directory)
  2. cleanDirectory(File directory)
  3. cleanDirectory(String directory)
  4. cleanDirectory(final File directory)