/** * Deletes the directory and all files inside it. If any file delete fails, they will be scheduled for deletion using {@link java.io.File#deleteOnExit()} */ public void close() { try { FileUtils.delete(true,(File) this); } catch (IOException e) { // } }
/** * Same as invoking {@link #delete(boolean, File...)} with deleteOnExit set to true)} * * @param file File to delete */ public static void delete(File... file) throws IOException { delete(true, file); }
/** * Same as invoking {@link #delete(boolean, File...)} with deleteOnExit set to true)} * * @param file File to delete */ public static void delete(File... file) throws IOException { delete(true, file); }
/** * Deletes the directory and all files inside it. If any file delete fails, they will be scheduled for deletion using {@link java.io.File#deleteOnExit()} */ public void close() { try { FileUtils.delete(true,(File) this); } catch (IOException e) { // } }
/** * Delete files/directories * * @param files files or directories to delete * @param deleteOnExit If true and deleting a file fails, it will schedule the file to delete on JVM exit rather than throw an exception */ public static void delete(boolean deleteOnExit, File... files) throws IOException { for (File file : files) { if (file != null && file.exists()) { if (file.isDirectory()) { File[] childrens = file.listFiles(); if (childrens == null) { throw new IOException("Unable to list files in " + file.getPath()); } for (File f : childrens) { delete(deleteOnExit, f); } } if (!file.delete()) { if (deleteOnExit) { file.deleteOnExit(); } else { throw new IOException("Unable to delete: " + file.getPath()); } } } } }
/** * Delete files/directories * * @param files files or directories to delete * @param deleteOnExit If true and deleting a file fails, it will schedule the file to delete on JVM exit rather than throw an exception */ public static void delete(boolean deleteOnExit, File... files) throws IOException { for (File file : files) { if (file != null && file.exists()) { if (file.isDirectory()) { File[] childrens = file.listFiles(); if (childrens == null) { throw new IOException("Unable to list files in " + file.getPath()); } for (File f : childrens) { delete(deleteOnExit, f); } } if (!file.delete()) { if (deleteOnExit) { file.deleteOnExit(); } else { throw new IOException("Unable to delete: " + file.getPath()); } } } } } }
try { tmp = File.createTempFile(prefix, suffix, directory); FileUtils.delete(tmp); if (!tmp.mkdir()) { throw new IOException("Unable to create temp dir: " + tmp.getPath()); } catch (IOException e) { try { FileUtils.delete(tmp); } catch (IOException ex) { throw new IOException("An error occured while creating temporary directory, and was unable to delete it afterwards",ex); } catch (RuntimeException e) { try { FileUtils.delete(tmp); } catch (IOException ex) { throw new IOException("An error occured while creating temporary directory, and was unable to delete it afterwards",ex);
try { tmp = File.createTempFile(prefix, suffix, directory); FileUtils.delete(tmp); if (!tmp.mkdir()) { throw new IOException("Unable to create temp dir: " + tmp.getPath()); } catch (IOException e) { try { FileUtils.delete(tmp); } catch (IOException ex) { throw new IOException("An error occured while creating temporary directory, and was unable to delete it afterwards",ex); } catch (RuntimeException e) { try { FileUtils.delete(tmp); } catch (IOException ex) { throw new IOException("An error occured while creating temporary directory, and was unable to delete it afterwards",ex);