Here you can find the source of delete(File f)
Parameter | Description |
---|---|
f | The file or directory to be deleted |
Parameter | Description |
---|---|
RuntimeException | if the file or directory could not be deleted |
public static void delete(File f)
//package com.java2s; //License from project: Apache License import java.io.File; public class Main { /**//from w w w . jav a 2 s. co m * Delete a file or directory * @param f The file or directory to be deleted * @throws RuntimeException if the file or directory could not be deleted */ public static void delete(File f) { delete_(f, false); } private static boolean delete_(File f, boolean silent) { boolean ok = true; if (f.exists()) { if (f.isDirectory()) { for (File c : f.listFiles()) { ok = ok && delete_(c, silent); } } try { boolean deleted = f.delete(); ok = ok && deleted; if (!deleted && !silent) { throw new RuntimeException("Failed to delete file or directory: " + f.getPath()); } } catch (Exception ex) { ok = false; if (!silent) { throw new RuntimeException("Failed to delete file or directory: " + f.getPath(), ex); } } } return ok; } }