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 deleteFolder(File fileOrDirectory) {
    if (fileOrDirectory.isDirectory()) {
        for (File child : fileOrDirectory.listFiles())
            deleteFolder(child);/*w  w  w  .j  ava 2s. c  om*/
    }
    fileOrDirectory.delete();
}

From source file:Main.java

public static void deleteDirectory(File directory) {
    if (directory.exists()) {
        File[] files = directory.listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.isDirectory()) {
                    deleteDirectory(file);
                } else {
                    file.delete();
                }/*from www  .  j a v a  2  s .co m*/
            }
        }
    }
    directory.delete();
}

From source file:com.uas.Files.FilesDAO.java

public static void deleteAll(File folder) {
    File[] files = folder.listFiles();
    if (files != null) { //some JVMs return null for empty dirs
        for (File f : files) {

            f.delete();

        }//from   w  w  w .j  a  v a  2 s  .  c o  m
    }

}

From source file:Main.java

public static void deleteFile2(File file) {

    // Log.i(TAG, "delete file path=" + file.getAbsolutePath());

    if (file.exists()) {
        if (file.isFile()) {
            file.delete();
        } else if (file.isDirectory()) {
            File files[] = file.listFiles();
            for (int i = 0; i < files.length; i++) {
                deleteFile2(files[i]);/* ww  w .  java 2  s.  co m*/
            }
        }
        file.delete();
    } else {
        // Log.e(TAG, "delete file no exists " + file.getAbsolutePath());
    }
}

From source file:Main.java

private static boolean checkFsWritable() {
    // Create a temporary file to see whether a volume is really writeable.
    // It's important not to put it in the root directory which may have a
    // limit on the number of files.
    String directoryName = Environment.getExternalStorageDirectory().toString() + "/DCIM";
    File directory = new File(directoryName);
    if (!directory.isDirectory()) {
        if (!directory.mkdirs()) {
            return false;
        }//from  ww  w .  j ava 2s  .  co m
    }
    File f = new File(directoryName, ".probe");
    try {
        // Remove stale file if any
        if (f.exists()) {
            f.delete();
        }
        if (!f.createNewFile()) {
            return false;
        }
        f.delete();
        return true;
    } catch (IOException ex) {
        return false;
    }
}

From source file:Main.java

public static boolean deleteFiles(String path) {
    File file = new File(path);
    boolean flag = false;
    if (file == null) {
        return flag;
    }/*from w ww.  j a  va  2 s.  c om*/
    if (file.isFile()) {
        file.delete();
    } else if (file.isDirectory()) {
        File[] fileList = file.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            flag = deleteFiles(fileList[i].getAbsolutePath());
            //            if(!flag){
            //               break;
            //            }
        }
    }
    return flag;
}

From source file:Main.java

public static void saveBitmap(String dirpath, String filename, Bitmap bitmap, boolean isDelete) {
    File dir = new File(dirpath);
    if (!dir.exists()) {
        dir.mkdirs();// w  ww.  j a va2s.  com
    }

    File file = new File(dirpath, filename);
    if (isDelete) {
        if (file.exists()) {
            file.delete();
        }
    }

    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    FileOutputStream out = null;
    try {
        out = new FileOutputStream(file);
        if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)) {
            out.flush();
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:com.sarm.Travelogue.process.DestinationProcessorRegressorTest.java

@AfterClass
public static void tearDownClass() {

    logger.info("Tearing down DestinationProcessorTest and deleting the 30000dests.xml file");
    File file = new File(regressDestinationfile);
    file.delete();

}

From source file:Main.java

private static boolean clearFile(File file, long date, int day) {
    if ((file != null) && (file.exists()) && (file.isFile())
            && ((date - file.lastModified()) / 86400000L > day)) {
        return file.delete();
    }// www.  j  av a  2 s .c o m
    return false;
}

From source file:Main.java

public static void deleteFilesInCache() {
    if (filesInCache == null) {
        return;//  ww w .  ja  v  a  2  s  .com
    } else {
        for (File file : filesInCache) {
            if (!file.exists())
                continue;
            if (file.isFile()) {
                file.delete();
            } else if (file.isDirectory()) {
                File[] files = file.listFiles();
                for (int i = 0; i < files.length; i++) {
                    if (!files[i].exists())
                        continue;
                    if (files[i].isFile()) {
                        files[i].delete();
                    }
                }
            }
        }
    }
    filesInCache.clear();
}