FileUtil { public static void mkdirs(final File dir) { if (!dir.isDirectory()) { if (!doMkdirs(null, dir, MKDIR_RETRY_COUNT)) { throw new FileUtilException("Unable to make directory: " + dir.getAbsolutePath()); } if (!dir.isDirectory()) { throw new FileUtilException("Directory not found: " + dir.getAbsolutePath()); } } } private  FileUtil(); static Path getInitialTempPath(); static Path getTempPath(); static File getInitialTempDir(); static File getTempDir(); static void forgetTempDir(); static void createNewFile(final File file); static void deleteFile(final File file); static void forceDelete(final File file); static void mkdirs(final File dir); static boolean doMkdirs(final File superDir, final File dir, int retry); static String getCanonicalPath(final File file);  }
@Test public void testMkdirs() throws IOException { final String tempDir = getCurrentTestPath().toAbsolutePath().toString(); final String rootDir = tempDir + "/TestFileUtil_" + System.currentTimeMillis(); final String[] dirArray = new String[10]; for (int i = 0; i < dirArray.length; i++) { dirArray[i] = buildDir(rootDir); } final AtomicBoolean exception = new AtomicBoolean(false); final SimpleExecutor simpleExecutor = new SimpleExecutor(4); for (int i = 0; i < 200; i++) { final int count = i; simpleExecutor.execute(() -> { try { final String dir = dirArray[count % dirArray.length]; System.out.println(dir); FileUtil.mkdirs(new File(dir)); } catch (final Exception ex) { ex.printStackTrace(); exception.set(true); } }); } simpleExecutor.waitForComplete(); simpleExecutor.stop(false); Assert.assertEquals(false, exception.get()); FileUtils.deleteDirectory(new File(rootDir)); }
@Test public void testMkdirsUnableToCreate() { try { FileUtil.mkdirs(new File("/dev/null")); Assert.fail("Not expecting that this directory can be created"); } catch (final Exception ex) { } }