public static File mkdir(final File file) { if (file.exists()) { return file; } hackJDK4715154(); if (!file.mkdirs()) { throw new FileRuntimeException("Cannot mkdir: " + file.getAbsolutePath()); } return file; }
public static File mkdirs(final File file) { if (!file.exists()) { hackJDK4715154(); if (!file.mkdirs()) { throw new FileRuntimeException("Cannot mkdirs: " + file.getAbsolutePath()); } return file; } return dir(file); }
/** * Delete a file and all contents if specified file is a directory * * @param file File * @Throws IllegalStateException on failure at any point */ public static void remove(final File file) { if (null != file && file.exists()) { if (file.isDirectory()) { final File[] files = file.listFiles(); if (files != null) { for (final File child : files) { remove(child); } } } hackJDK4715154(); if (!file.delete()) { throw new IllegalStateException("Could not delete file: " + file.getAbsolutePath()); } } }
/** * Delete a file and all contents if specified file is a directory. * If the delete fails then the file/s are flagged for delete on exit. * * @param file File */ public static void delete(final File file) { if (null != file && file.exists()) { if (file.isDirectory()) { final File[] files = file.listFiles(); if (null != files) { for (final File f : files) { delete(f); } } } try { hackJDK4715154(); if (!file.delete()) { file.deleteOnExit(); } } catch (final Throwable e) { //Ignore } } }
public static File tmpdir() { try { File file; try { file = File.createTempFile("temp", "dir"); } catch (final Throwable e) { //Use a local tmp directory final File tmp = new File("tmp"); hackJDK4715154(); if (!tmp.exists() && !tmp.mkdirs()) { throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath()); } file = File.createTempFile("temp", "dir", tmp); } hackJDK4715154(); if (!file.delete()) { throw new IOException("Failed to create temp dir. Delete failed"); } mkdir(file); deleteOnExit(file); return file; } catch (final IOException e) { throw new FileRuntimeException(e); } }