List of usage examples for java.io File delete
public boolean delete()
From source file:Main.java
public static void fileDelete(File cacheDir) { if (imageNumber < 30) return;/* w ww . j av a2 s . co m*/ File storage = cacheDir; String fileName = "temp" + imageNumber + ".jpg"; File tempFile = new File(storage, fileName); if (tempFile.exists()) { tempFile.delete(); } }
From source file:Main.java
public static void deleteExternalStoragePrivateFile(Context appCtx, String fileName) { // Get path for the file on external storage. If external // storage is not currently mounted this will fail. File file = new File(appCtx.getExternalFilesDir(null), fileName); if (file != null) { file.delete(); }/*from www . jav a2 s .co m*/ }
From source file:Main.java
public static void deleteFiles(List<File> selectedFiles) { if (selectedFiles != null & selectedFiles.size() > 0) { for (File file : selectedFiles) { if (file.isFile()) { file.delete(); } else { deleteDir(file);/*from www . ja v a 2 s.c o m*/ // file.delete(); } } } }
From source file:com.orchestra.portale.utils.InsertUtils.java
public static String delimg(HttpServletRequest request, String id, String nameimg) { String esito = ""; HttpSession session = request.getSession(); ServletContext sc = session.getServletContext(); File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "poi" + File.separator + "img" + File.separator + id); File img = new File(dir.getAbsolutePath() + File.separator + nameimg); if (img.delete()) esito = "OK"; else/* ww w . j a va 2 s.c o m*/ esito = "ERRORE"; return esito; }
From source file:Main.java
private static boolean deleteFileSafely(File file) { if (file != null) { String tmpPath = file.getAbsolutePath() + System.currentTimeMillis(); File tmp = new File(tmpPath); boolean result = file.renameTo(tmp); return result && tmp.delete(); }//from w w w . j ava2 s. c om return false; }
From source file:Main.java
public static void saveImage(Bitmap bmp) { String root = Environment.getExternalStorageDirectory().toString(); File myDir = new File(root + "/abcxyz"); myDir.mkdirs();// www . ja v a2 s. co m Random generator = new Random(); int n = 10000; n = generator.nextInt(n); String name = "Image-" + n + ".jpg"; File file = new File(myDir, name); if (file.exists()) file.delete(); try { FileOutputStream out = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:Main.java
public static boolean deleteFolder(File folder) { if (!folder.exists()) { return true; }//w w w.jav a 2s. c o m File[] subFiles = folder.listFiles(); if (subFiles != null) { for (File f : subFiles) { if (f.isFile()) { if (!f.delete()) { return false; } } else { if (!deleteFolder(f)) { return false; } } } } return folder.delete(); }
From source file:com.adaptris.core.stubs.TempFileUtils.java
public static File createTrackedFile(String prefix, String suffix, File baseDir, Object tracker) throws IOException { File f = File.createTempFile(prefix, suffix, baseDir); f.delete(); return trackFile(f, tracker); }
From source file:Main.java
public static void rename(File oldFile, File newFile) { if (newFile.exists() && !newFile.delete()) { throw new RuntimeException("can not del dest file: " + newFile); }// ww w.j a v a 2 s. co m if (!oldFile.renameTo(newFile)) { try { copy(oldFile, newFile); if (!oldFile.delete()) { // this is not so bad, but still very strange System.err.println("can not del source file: " + oldFile); } } catch (Exception ex) { throw new RuntimeException("rename failed: from: " + oldFile + " to: " + newFile, ex); } } }
From source file:Main.java
@SuppressWarnings("ResultOfMethodCallIgnored") public static boolean saveBitmap(Bitmap bitmap, String filePath, int quality) { boolean result = false; FileOutputStream fileOutputStream = null; try {//from www . j av a 2 s .c o m File file = new File(filePath); if (file.exists()) file.delete(); fileOutputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, quality, fileOutputStream); fileOutputStream.flush(); result = true; } catch (IOException ignored) { } finally { if (fileOutputStream != null) { try { fileOutputStream.close(); } catch (IOException ignored) { } } } return result; }