Java Create Directory mkdirsOrFail(File dirFile)

Here you can find the source of mkdirsOrFail(File dirFile)

Description

Check if given file is directory and try to create it if not.

License

Apache License

Parameter

Parameter Description
dirFile directory to be created (may be null )

Exception

Parameter Description
IOException Creation of directory was not successful

Declaration

private static void mkdirsOrFail(File dirFile) throws IOException 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;

import java.io.IOException;

public class Main {
    /**//from   ww  w  .ja v  a 2 s.  co  m
     * Check if given file is directory and try to create it if not. It throws {@link IOException} if the directory doesn't
     * exist and it's not possible to create it.
     *
     * @param dirFile directory to be created (may be {@code null})
     * @throws IOException Creation of directory was not successful
     */
    private static void mkdirsOrFail(File dirFile) throws IOException {
        if (dirFile == null) {
            return;
        }

        if (!dirFile.isDirectory()) {
            if (!dirFile.mkdirs()) {
                throw new IOException(
                        "Directory doesn't exist and its creation failed: " + dirFile.getAbsolutePath());
            }
        }
    }
}

Related

  1. mkdirsIfAbsent(String pathname)
  2. mkdirsIfNotExists(String pathname)
  3. mkdirsifnotExists(String s)
  4. mkdirsInRemote(String host, String path, boolean deleteIfExisted)
  5. mkdirsOrCrash(File d)
  6. mkdirsWithExistsCheck(File dir)
  7. mkdirsWithRetry(final File f)