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 saveImage(File file, byte[] bytes) throws Exception {
    file.delete();
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(bytes);/*from  w  ww  .j av a 2  s. c  om*/
    fos.flush();
    fos.close();
}

From source file:Main.java

public static void clearTemp(Activity activity) {
    File folder = new File(activity.getExternalFilesDir(null), "temp");
    if (null != folder.listFiles()) {
        for (File file : folder.listFiles()) {
            file.delete();
        }/*from  www .  ja  v  a 2 s .  c o m*/
    }
}

From source file:Main.java

public static void deleteFiles(String relativePath) {
    //      File dir = new File(path);
    File dir = creatSDDir(relativePath);
    if (dir.isDirectory()) {
        File[] files = dir.listFiles();
        for (File file : files) {
            file.delete();
        }//from  w  ww  . j a  v  a2s .c o  m
    }
}

From source file:Main.java

public static void removeFavNodes(Context cxt) {
    File data = cxt.getFileStreamPath(key_fav_nodes);
    data.delete();
}

From source file:Main.java

public static void delete(File f) {
    if ((f != null) && (f.exists()) && (!(f.delete()))) {
        throw new RuntimeException(f.getAbsolutePath() + " doesn't be deleted!");
    }/*  w  w w  .  j a  v  a 2  s.  c o m*/

}

From source file:Main.java

public static void recursiveFileRemoval(File root) {
    if (!root.delete()) {
        if (root.isDirectory()) {
            File[] files = root.listFiles();
            if (files != null) {
                for (File f : files) {
                    recursiveFileRemoval(f);
                }//from w  w w .  j av a2  s . co m
            }
        }
    }
}

From source file:Main.java

public static void deleteFilesByDirectory(File directory) {
    if (directory != null && directory.exists() && directory.isDirectory()) {
        for (File item : directory.listFiles()) {
            item.delete();
        }//from w w w.  j  a va  2s  .  co  m
    }
}

From source file:Main.java

private static void deleteFilesByDirectory(File directory) {
    if (directory != null && directory.exists() && directory.isDirectory()) {
        for (File item : directory.listFiles()) {
            item.delete();
        }/*from  w ww  .  j  ava2 s .com*/
    }
}

From source file:Main.java

public static boolean deleteFile(File file) throws IOException {
    return file != null && file.delete();
}

From source file:Main.java

public static void deleteFile(String path) {
    File file = new File(path);
    if (file.isDirectory()) {//delete dir
        File[] childFile = file.listFiles();
        for (File tempFile : childFile) {
            tempFile.delete();
        }//from   w w  w. j a va 2s.c  o m
        file.delete();
    } else {//delete file
        file.delete();
    }
}