List of usage examples for java.io File delete
public boolean delete()
From source file:nl.knaw.dans.easy.sword2examples.SimpleDeposit.java
public static URI depositPackage(File bagDir, IRI colIri, String uid, String pw) throws Exception { // 0. Zip the bagDir File zipFile = new File(bagDir.getAbsolutePath() + ".zip"); zipFile.delete(); Common.zipDirectory(bagDir, zipFile); // 1. Set up stream for calculating MD5 MessageDigest md = MessageDigest.getInstance("MD5"); try (FileInputStream fis = new FileInputStream(zipFile); DigestInputStream dis = new DigestInputStream(fis, md)) { // 2. Post entire bag to Col-IRI CloseableHttpClient http = Common.createHttpClient(colIri.toURI(), uid, pw); CloseableHttpResponse response = Common.sendChunk(dis, (int) zipFile.length(), "POST", colIri.toURI(), "bag.zip", "application/zip", http, false); // 3. Check the response. If transfer corrupt (MD5 doesn't check out), report and exit. String bodyText = Common.readEntityAsString(response.getEntity()); if (response.getStatusLine().getStatusCode() != 201) { System.err.println("FAILED. Status = " + response.getStatusLine()); System.err.println("Response body follows:"); System.err.println(bodyText); System.exit(2);/*from w w w . j a va 2 s . c o m*/ } System.out.println("SUCCESS. Deposit receipt follows:"); System.out.println(bodyText); // 4. Get the statement URL. This is the URL from which to retrieve the current status of the deposit. System.out.println("Retrieving Statement IRI (Stat-IRI) from deposit receipt ..."); Entry receipt = Common.parse(bodyText); Link statLink = receipt.getLink("http://purl.org/net/sword/terms/statement"); IRI statIri = statLink.getHref(); System.out.println("Stat-IRI = " + statIri); // 5. Check statement every ten seconds (a bit too frantic, but okay for this test). If status changes: // report new status. If status is an error (INVALID, REJECTED, FAILED) or ARCHIVED: exit. return Common.trackDeposit(http, statIri.toURI()); } }
From source file:Main.java
public static boolean delSDFile(String filePath) { File file = new File(filePath); if (file == null || !file.exists() || file.isDirectory()) return false; file.delete(); return true;/* w w w . ja v a 2 s .c o m*/ }
From source file:Main.java
private static InputStream bitmap2InputStream(Context context, Bitmap bitmap) throws IOException { File file = new File(context.getFilesDir(), "wallpaper.jpg"); if (file.exists()) { file.delete(); }/* w ww. j a v a2 s . c om*/ file.createNewFile(); FileOutputStream fileOutputStream = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fileOutputStream); fileOutputStream.close(); return filePath2InputStream(file.getAbsolutePath()); }
From source file:Main.java
public static void removeFileAccountInfo(Context ctx) { File accountFile = ctx.getFileStreamPath(ACCOUNT_PREFERENCE); if (accountFile != null && accountFile.exists()) { accountFile.delete(); }/*from w w w.j ava 2 s. co m*/ }
From source file:Main.java
/** * Save {@link String} to {@link File} witht the specified encoding * * @param string {@link String}/*from www . j a va2 s. c om*/ * @param path Path of the file * @param string Encoding * @throws IOException */ public static void saveStringToFile(String string, File path, String encoding) throws IOException { if (path.exists()) { path.delete(); } if ((path.getParentFile().mkdirs() || path.getParentFile().exists()) && (path.exists() || path.createNewFile())) { Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), encoding)); writer.write(string); writer.close(); } }
From source file:Main.java
public static void write(String in, File file, boolean append) { if (file.exists()) { file.delete(); }/*from w ww. j a va2s. c o m*/ try { file.createNewFile(); FileWriter fw = new FileWriter(file, append); fw.write(in); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.fhg.iais.commons.stream.AutoFileOutputStream.java
private static boolean deleteFile(File f) { return (f == null) || f.delete() || !f.exists(); }
From source file:Main.java
public static boolean deleteFile(final String fileName) { if (TextUtils.isEmpty(fileName)) { return false; }/*from ww w .j a va 2s. c om*/ boolean result = false; File file = new File(fileName); if (file.isFile() && file.exists()) { result = file.delete(); } return result; }
From source file:Main.java
static public void deleteReceiptImage(Context ctxt, int tripId, String imgName) { File file = new File(ctxt.getExternalFilesDir(null) + "/" + tripId, imgName); if (file.exists()) { boolean test = file.delete(); assert test; }/*from w w w. j a va 2 s .c o m*/ }
From source file:Main.java
public static void saveBitmap(String filename, Bitmap bitmap) throws Exception { File file = new File(sAppContext.getCacheDir().getPath() + "/" + filename); if (file.exists()) { file.delete(); }/*w w w . j av a 2 s .c om*/ file.createNewFile(); FileOutputStream fos = new FileOutputStream(file); bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); }