public static File tmpdir() { try { File file = null; try { file = File.createTempFile("temp", "dir"); } catch (Throwable e) { // Use a local tmp directory final File tmp = new File("tmp"); if (!tmp.exists() && !tmp.mkdirs()) { throw new IOException("Failed to create local tmp directory: " + tmp.getAbsolutePath()); } file = File.createTempFile("temp", "dir", tmp); } if (!file.delete()) { throw new IOException("Failed to create temp dir. Delete failed"); } mkdir(file); deleteOnExit(file); return file; } catch (IOException e) { throw new FileRuntimeException(e); } }