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

private static void deleteDirectory(File directory) {
    if (directory.isDirectory()) {
        for (String item : directory.list()) {
            new File(directory, item).delete();
        }//ww w . j av  a  2s .  c o  m
        directory.delete();
    }
}

From source file:com.xebialabs.deployit.cli.ext.mustachify.io.Files2.java

public static boolean delete(@Nullable File file) {
    if (file != null) {
        return file.delete();
    }//  ww w.  j av a 2 s . c o m
    return false;
}

From source file:Main.java

public static void deleteRecursive(File fileOrDirectory) {

    if (fileOrDirectory.isDirectory())
        for (File child : fileOrDirectory.listFiles())
            deleteRecursive(child);//ww w  . j a  va2s  .  c om

    fileOrDirectory.delete();

}

From source file:com.github.aliakhtar.annoTest.util.Compiler.java

private static File createTempDir(String prefix) throws IOException {
    File file = File.createTempFile(prefix, null);
    if (!file.delete()) {
        throw new IOException("Unable to delete temporary file " + file.getAbsolutePath());
    }/*from ww  w . j  a  v a2s .com*/
    if (!file.mkdir()) {
        throw new IOException("Unable to create temp directory " + file.getAbsolutePath());
    }
    return file;
}

From source file:melnorme.utilbox.misc.FileUtil.java

public static boolean deleteIfExists(File path) throws IOException {
    if (path.exists()) {
        return path.delete();
    }/*  w ww  .java  2  s  . co m*/

    return false;
}

From source file:net.itransformers.idiscover.v2.core.listeners.GraphmlFileLogGroovyDiscoveryListenerTestCase.java

public static File createTempDirectory() throws IOException {
    final File temp = File.createTempFile("temp", Long.toString(System.nanoTime()));
    if (!(temp.delete())) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }//from w  ww . jav a 2  s .  c om

    if (!(temp.mkdir())) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }

    return temp;
}

From source file:Main.java

public static boolean deleteFileRecursively(String path) {
    File destFile = new File(path);
    if (!destFile.exists()) {
        return true;
    }//from  w ww  .  j ava2s  .  c o  m

    if (destFile.isFile()) {
        destFile.delete();
        return true;
    }

    String[] childNames = destFile.list();
    for (String child : childNames) {
        if (!deleteFileRecursively(new File(path, child).getAbsolutePath())) {
            return false;
        }
    }
    return destFile.delete();
}

From source file:com.genericworkflownodes.knime.custom.ZipUtilsTest.java

public static File createTempDirectory() throws IOException {
    final File temp;

    temp = File.createTempFile("temp", Long.toString(System.nanoTime()));

    if (!(temp.delete())) {
        throw new IOException("Could not delete temp file: " + temp.getAbsolutePath());
    }// w  w w.  j ava 2s  . c  om

    if (!(temp.mkdir())) {
        throw new IOException("Could not create temp directory: " + temp.getAbsolutePath());
    }

    return (temp);
}

From source file:Main.java

public static void deleteRecursive(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory())
        for (File child : fileOrDirectory.listFiles()) {
            deleteRecursive(child);//ww w  .  j  a v a 2  s.c o  m
        }

    fileOrDirectory.delete();
}

From source file:Main.java

/**
 * Delete corresponding path, file or directory.
 *
 * @param file      path to delete./*from   ww w  . j  a va 2  s. c  om*/
 * @param ignoreDir whether ignore directory. If true, all files will be deleted while directories is reserved.
 */
public static void delete(File file, boolean ignoreDir) {
    if (file == null || !file.exists()) {
        return;
    }
    if (file.isFile()) {
        file.delete();
        return;
    }

    File[] fileList = file.listFiles();
    if (fileList == null) {
        return;
    }

    for (File f : fileList) {
        delete(f, ignoreDir);
    }
    // delete the folder if need.
    if (!ignoreDir)
        file.delete();
}