List of usage examples for java.io File delete
public boolean delete()
From source file:Main.java
public static void deleteFile(final File dir) { if (!dir.exists()) { return;// w w w . j a v a2 s . com } if (dir.isDirectory()) { final File[] filies = dir.listFiles(); for (int i = 0; i < filies.length; i++) { final File curFile = filies[i]; if (curFile.isDirectory()) { deleteFile(curFile); } else { curFile.delete(); } } dir.delete(); } }
From source file:Main.java
public static void deleteTempPackageFile(Context context, String pathOnSDCard) { File file = new File(pathOnSDCard); File tmpPackageFile = context.getFileStreamPath(file.getName()); if (tmpPackageFile == null) { return;//from w w w.j av a2 s .co m } if (tmpPackageFile.exists()) { tmpPackageFile.delete(); } }
From source file:Main.java
public static boolean deleteFiles(String folder) { if (folder == null || folder.length() == 0 || folder.trim().length() == 0) { return true; }/*from w w w . j av a 2s . co m*/ File file = new File(folder); if (!file.exists()) { return true; } if (file.isFile()) { return file.delete(); } if (!file.isDirectory()) { return false; } for (File f : file.listFiles()) { if (f.isFile()) { f.delete(); } else if (f.isDirectory()) { deleteFile(f.getAbsolutePath()); } } return file.delete(); }
From source file:Main.java
public static File createFolders() { File baseDir;//from www . ja v a 2 s.co m if (android.os.Build.VERSION.SDK_INT < 8) { baseDir = Environment.getExternalStorageDirectory(); } else { baseDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); } if (baseDir == null) return Environment.getExternalStorageDirectory(); File aviaryFolder = new File(baseDir, FOLDER_NAME); if (aviaryFolder.exists()) return aviaryFolder; if (aviaryFolder.isFile()) aviaryFolder.delete(); if (aviaryFolder.mkdirs()) return aviaryFolder; return Environment.getExternalStorageDirectory(); }
From source file:Main.java
/** * Deletes the specified diretory and any files and directories in it * recursively.//from w ww. j ava 2 s.c o m * * @param dir The directory to remove. * @throws IOException If the directory could not be removed. */ public static void deleteDir(File dir) throws IOException { if (!dir.isDirectory()) { throw new IOException("Not a directory " + dir); } File[] files = dir.listFiles(); for (int i = 0; i < files.length; i++) { File file = files[i]; if (file.isDirectory()) { deleteDir(file); } else { boolean deleted = file.delete(); if (!deleted) { throw new IOException("Unable to delete file" + file); } } } dir.delete(); }
From source file:brut.util.OS.java
public static File createTempDirectory() throws BrutException { try {/*from w w w . j a v a2 s . c o m*/ File tmp = File.createTempFile("BRUT", null); if (!tmp.delete()) { throw new BrutException("Could not delete tmp file: " + tmp.getAbsolutePath()); } if (!tmp.mkdir()) { throw new BrutException("Could not create tmp dir: " + tmp.getAbsolutePath()); } return tmp; } catch (IOException ex) { throw new BrutException("Could not create tmp dir", ex); } }
From source file:de.mendelson.comm.as2.AS2.java
public static void cleanup() { // RJC: Runtime creates database, lock, and log artifacts. During // development time this is very annoying. Temporarily cleaning // up these artifacts... // TODO better solution at some point (need persistent state) String RUNTIME_ARTIFACTS[] = new String[] { "AS2_DB_CONFIG.log", "AS2_DB_CONFIG.script", "AS2_DB_RUNTIME.log", "AS2_DB_RUNTIME.script", "client_server_session0.logd", "client_server_session1.logd", "client_server_session2.logd", "AS2_DB_CONFIG.properties", "AS2_DB_CONFIG.tmp", "AS2_DB_RUNTIME.properties", "AS2_DB_RUNTIME.tmp", "client_server_session0.log.lck", "client_server_session1.log.lck", "client_server_session2.log.lck", "mendelson_opensource_AS2.lock", "messages", "AS2_DB_CONFIG.properties", "AS2_DB_CONFIG.script", "AS2_DB_RUNTIME.properties", "AS2_DB_RUNTIME.script", "client_server_session0.log.lck", "client_server_session0.log" }; for (String s : RUNTIME_ARTIFACTS) { File f = new File(s); if (f.isFile()) { f.delete(); } else {/*from w w w.j av a2 s .co m*/ if (f.isDirectory()) { try { FileUtils.deleteDirectory(f); } catch (IOException e) { e.printStackTrace(); } } } } }
From source file:gov.wa.wsdot.cms.utils.Migration.java
/** * Delete resource files named after GUIDs. *///w w w. j a v a 2 s. c o m public static void deleteResources(String archiveFolder) { File files[] = (new File(archiveFolder)).listFiles(new FilenameFilter() { @Override public boolean accept(File archiveFolder, String name) { return name.matches("res[A-Z0-9]{32}.*"); } }); System.out.println("Deleting resources."); for (File file : files) { if (!file.delete()) { System.out.println("Can't remove: " + file.getAbsolutePath()); } else { System.out.println("Removed: " + file.getAbsolutePath()); } } System.out.println("Done."); }
From source file:Main.java
public static Boolean canWrite(File f) { if (f.isDirectory()) { FileWriter w = null;// w ww . j a va 2s .co m String testFilename = f.getPath() + "/.EASYRPG_WRITE_TEST"; try { w = new FileWriter(testFilename); // Permissions are checked on open, but it is Android, better be save w.write("Android >.<"); } catch (IOException e) { return false; } finally { try { if (w != null) { w.close(); } } catch (IOException e) { } } File testFile = new File(testFilename); if (testFile.exists()) { // Does not throw testFile.delete(); } } else { boolean deleteAfter = f.exists(); try { FileWriter w = new FileWriter(f, true); w.close(); } catch (IOException e) { return false; } if (deleteAfter) { f.delete(); } } return true; }
From source file:Main.java
/** * //from ww w . j a v a 2s.c o m * @param f */ public static void deleteDir(File f) { try { if (f.isDirectory()) { for (File c : f.listFiles()) { deleteDir(c); } } f.delete(); } catch (Exception e) { } }