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:msuresh.raftdistdb.AtomixDB.java

public static void delete(File path) throws FileNotFoundException {
    if (!path.exists())
        throw new FileNotFoundException(path.getAbsolutePath());
    for (File f : path.listFiles()) {
        f.delete();
    }//from   w ww.  ja  v a 2 s. com

}

From source file:net.bpelunit.util.FileUtil.java

public static File createTempDirectory() throws IOException {
    File tmp = File.createTempFile("bpelunit", "");
    tmp.delete();
    tmp.mkdir();/*from   w  ww.  j  a  v a2 s  .  co m*/
    return tmp;
}

From source file:Main.java

private static void deleteFileOrDirectory(File file) {
    if (file.isDirectory()) {
        File[] subFiles = file.listFiles();
        for (File sf : subFiles) {
            if (sf.isFile()) {
                sf.delete();
            } else {
                deleteFileOrDirectory(sf);
            }//from  w  w w . jav a  2  s. c o  m
        }
    }
    file.delete();
}

From source file:Main.java

public static void deleteFile(String path) {
    File file = new File(path);

    if (file.exists()) {
        file.delete();
    }/*  w  w  w  . ja va  2s.c o m*/
}

From source file:Main.java

public static void clearDirectory(File dir) {
    String[] list = dir.list();/*w w w  . ja v a  2 s .com*/
    if (list != null) {
        for (int i = 0; i < list.length; i++) {
            File file = new File(dir, list[i]);
            file.delete();
        }
    }
}

From source file:Main.java

public static void deleteFiles(String path, String name) {
    File sharedPrefsDir = new File(path);
    File[] files = sharedPrefsDir.listFiles();
    for (File file : files) {
        if (file.getName().endsWith(name)) {
            file.delete();
        }//w  w  w . ja  va  2s. c o  m
    }
}

From source file:name.milesparker.gerrit.analysis.CollectGit.java

protected static void deleteContents(String dataDirectory) {
    File dir = new File(dataDirectory);
    for (File file : dir.listFiles()) {
        file.delete();
    }//from ww  w  . j av  a 2s . c om
}

From source file:Main.java

public static void cacheStringToFile(String str, String filename) {
    File f = new File(filename);
    if (f.exists()) {
        f.delete();
    }//from  ww  w. j  a  v  a2 s.  c o m
    try {
        f.createNewFile();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        FileOutputStream fos = new FileOutputStream(f, true);
        fos.write(str.getBytes());
        fos.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void deleteFile(String filePath) {
    try {/*  w  ww. j a  va2  s  .  c  om*/
        File delFile = new File(filePath);
        if (delFile.exists())
            delFile.delete();
    } catch (Exception e) {
        e.printStackTrace();

    }
}

From source file:Main.java

public static void defileFile(File file) {
    if (file.isFile()) {
        file.delete();
        return;/*ww  w  .  jav a 2  s .c  o  m*/
    }

    if (file.isDirectory()) {
        File[] childFiles = file.listFiles();
        if (childFiles == null || childFiles.length == 0) {
            file.delete();
            return;
        }

        for (File f : childFiles) {
            defileFile(f);
        }
        file.delete();
    }

}