Example usage for java.io File delete

List of usage examples for java.io File delete

Introduction

In this page you can find the example usage for java.io File delete.

Prototype

public boolean delete() 

Source Link

Document

Deletes the file or directory denoted by this abstract pathname.

Usage

From source file:Main.java

public static void deleteDir(File file) {
    if (file.exists()) {
        if (file.isDirectory()) {
            File[] files = file.listFiles();
            for (File subFile : files) {
                if (subFile.isDirectory())
                    deleteDir(subFile);/*  www. j av a  2s. co  m*/
                else
                    subFile.delete();
            }
        }
        file.delete();
    }
}

From source file:Main.java

private static void deleteFilesByDirectory(File directory) {
    if (directory != null && directory.exists() && directory.isDirectory()) {
        for (File item : directory.listFiles()) {
            if (item.isDirectory()) {
                deleteFilesByDirectory(item);
            }/*w  w w .  ja  va 2 s.c om*/
            item.delete();
        }
        directory.delete();
    }
}

From source file:Main.java

private static boolean deleteFilesInDir(final File dir) {
    if (dir == null)
        return false;
    // dir doesn't exist then return true
    if (!dir.exists())
        return true;
    // dir isn't a directory then return false
    if (!dir.isDirectory())
        return false;
    File[] files = dir.listFiles();
    if (files != null && files.length != 0) {
        for (File file : files) {
            if (file.isFile()) {
                if (!file.delete())
                    return false;
            } else if (file.isDirectory()) {
                if (!deleteDir(file))
                    return false;
            }/*www.  j a  va 2  s. co  m*/
        }
    }
    return true;
}

From source file:Main.java

private static boolean deleteDir(final File dir) {
    if (dir == null)
        return false;
    // dir doesn't exist then return true
    if (!dir.exists())
        return true;
    // dir isn't a directory then return false
    if (!dir.isDirectory())
        return false;
    File[] files = dir.listFiles();
    if (files != null && files.length != 0) {
        for (File file : files) {
            if (file.isFile()) {
                if (!file.delete())
                    return false;
            } else if (file.isDirectory()) {
                if (!deleteDir(file))
                    return false;
            }/*from   w ww .  j a v a  2 s.  c  o  m*/
        }
    }
    return dir.delete();
}

From source file:com.openmeap.model.ModelTestUtils.java

static public void resetTestDb() {
    if (persistenceBeans != null) {
        EntityManagerFactory emf = getEntityManagerFactory();
        emf.close();// w  ww . j a v  a  2  s.c o m
        persistenceBeans.close();
    }
    persistenceBeans = null;
    File testDbFile = new File(OPENMEAP_TEST_DB);
    if (testDbFile.exists() && !testDbFile.delete()) {
        throw new RuntimeException("Could not delete " + OPENMEAP_TEST_DB);
    }
}

From source file:Main.java

public static boolean deleteFile(File file) {
    if (sdState.equals(Environment.MEDIA_MOUNTED)) {
        if (file.exists()) {
            if (file.isFile()) {
                return file.delete();
            }//from w  w  w.  j  a v  a  2 s. c  om
        } else {
            return true; // file not exist
        }
    }
    return false;
}

From source file:Main.java

public static void deleteFile(String fileName) {
    File file = new File(
            Environment.getExternalStorageDirectory().getPath() + "/kidsedu/temp" + File.separator + fileName);
    if (file.exists()) {
        file.delete();
    }// w  w  w  .jav  a2  s.co  m
}

From source file:Main.java

public static void delete(File file) {
    if (file.isDirectory()) {
        File[] childs = file.listFiles();
        for (File file2 : childs)
            delete(file2);/*from   w  w w. j  a  v a 2  s  .  c o m*/
    }
    file.delete();
}

From source file:Main.java

public static void deleteFiles(String path, String excludeSuffix) {
    File dir = new File(path);
    File[] files = dir.listFiles();
    if (files != null && files.length > 0) {
        for (File file : files) {
            if (excludeSuffix != null && file.getName().contains(excludeSuffix)) {
                continue;
            }/*w  w w  .  jav  a 2 s. co m*/
            file.delete();
        }
    }
}

From source file:Main.java

public static void clearProjectData() {
    File pdf = new File(System.getProperty("msbSummary") + "." + System.getProperty("user.name"));

    if (pdf.exists() && pdf.canWrite()) {
        pdf.delete();
    }//ww w. j  a va  2 s  . c om
}