List of usage examples for java.io File delete
public boolean delete()
From source file:Main.java
private static File commit(String basename, File tmpFile) throws IOException { try {// www .j av a2 s . c om final String backupName = basename + "~"; final File desired = new File(basename); final File backup = new File(backupName); backup.delete(); if (desired.exists()) { if (!desired.renameTo(new File(backupName))) throw new IOException("can't rename to " + backupName); } if (!tmpFile.renameTo(new File(basename))) throw new IOException("can't rename to " + basename); } catch (IOException x) { tmpFile.delete(); throw x; } return new File(basename); }
From source file:Main.java
public static void removeUnusedTiles(Context mContext, final ArrayList<String> usedTiles) { // remove all files are stored in the tile path but are not used File folder = new File(mContext.getFilesDir(), TILE_PATH); File[] unused = folder.listFiles(new FilenameFilter() { @Override/*from w w w.j ava 2s. c o m*/ public boolean accept(File dir, String filename) { return !usedTiles.contains(filename); } }); if (unused != null) { for (File f : unused) { f.delete(); } } }
From source file:Main.java
public static void deleteDirectory(File file) { if (file.isFile()) { file.delete(); return;// ww w.j a v a 2 s. c o m } if (file.isDirectory()) { File[] childFiles = file.listFiles(); if (childFiles == null || childFiles.length == 0) { file.delete(); return; } for (int i = 0; i < childFiles.length; i++) { deleteDirectory(childFiles[i]); } file.delete(); } }
From source file:Main.java
public static void delete(File file) { if (file.isFile()) { file.delete(); return;//w w w. j a v a2s .c o m } if (file.isDirectory()) { File[] childFiles = file.listFiles(); if (childFiles == null || childFiles.length == 0) { file.delete(); return; } for (int i = 0; i < childFiles.length; i++) { delete(childFiles[i]); } file.delete(); } }
From source file:Main.java
public static final boolean deleteFolder(String path) { // not recursive if (path != null && storageReady()) { File dir = new File(path); if (dir.exists() && dir.isDirectory()) { File[] files = dir.listFiles(); for (File file : files) { if (!file.delete()) { Log.i(tag, "Failed to delete " + file); }//from w w w.ja v a 2 s .c om } } return dir.delete(); } else { return false; } }
From source file:Main.java
public static void deleteFile(String path) { if (path != null) { File file = new File(path); if (file.exists()) { file.delete(); }/* w w w .j a v a 2 s. c o m*/ } }
From source file:Main.java
public static void delFile(String path) { if (!TextUtils.isEmpty(path)) { File file = new File(path); if (file.exists()) { file.delete(); }/*from w ww.j a va2s . c o m*/ } }
From source file:Main.java
public static void deleteStar(String filename) throws Exception { File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename); file.delete(); }
From source file:Main.java
public static void deleteFilesByDirectory(File directory) { // LogUtil.e("TAG", "deleteFiles--directory:"+directory); // LogUtil.e("TAG", "deleteFiles--exists:"+directory.exists()); // LogUtil.e("TAG", "deleteFiles--isDirectory:"+directory.isDirectory()); if (directory != null && directory.exists() && directory.isDirectory()) { for (File item : directory.listFiles()) { Log.e("TAG", "deleteFiles--item:" + item); Log.e("TAG", "deleteFiles--item.isdir:" + item.isDirectory()); if (item != null && item.isDirectory()) { for (File itemsec : item.listFiles()) { itemsec.delete(); }// ww w . jav a 2 s . com } item.delete(); } } }
From source file:Main.java
public static void deleteFile(String filePath) { try {//from w w w. j a v a 2 s . co m File file = new File(filePath); if (file.exists()) file.delete(); } catch (Exception e) { e.printStackTrace(); } }