Java Utililty Methods Create Directory

List of utility methods to do Create Directory

Description

The list of methods to do Create Directory are organized into topic(s).

Method

BooleanmkdirIfMissing(File dir)
mkdir If Missing
return !dir.exists() && dir.mkdir();
intmkdirIfNotExists(File dir)
0: dir not created because it already exists 1: dir created -1: dir needs to be created, but failed
if (!dir.exists()) {
    if (dir.mkdirs()) {
        return 1;
    } else {
        return -1;
} else {
    return 0;
...
booleanmkDirRec(File file)
Creates all required directories for the provided file.
if (file == null)
    return true;
if (!file.exists()) {
    if (!mkDirRec(file.getParentFile()))
        return false;
    if (!file.mkdir())
        return false;
if (!file.isDirectory())
    return false;
return true;
voidmkdirs(File folder)
mkdirs
if (folder != null) {
    if (!folder.isDirectory()) {
        if (!folder.mkdirs()) {
            throw new RuntimeException("Unable to create directory " + folder.getAbsolutePath()); 
voidmkdirs(File outdir, String path)
mkdirs
File d = new File(outdir, path);
if (!d.exists())
    d.mkdirs();
Filemkdirs(File parent, String name, boolean mkdirs)
Creates and returns a File for the given path and name.
return mkdirs(new File(parent, name), mkdirs);
booleanmkDirs(File path)
mk Dirs
return path.mkdirs();
voidmkdirs(File path)
mkdirs
if (!path.mkdirs()) {
    throw new IOException("Can't create folder(s): " + path);
booleanmkdirs(File path)
File.mkdirs() method doesn't work when multiple threads are creating paths with a common parent directory simultaneously.
if (path.exists()) {
    return true;
if (path.mkdir() || path.exists()) {
    return true;
File canonFile = null;
try {
...
Filemkdirs(File path)
mkdirs
path = getCleanAbsolutePath(path);
if (!path.exists()) {
    if (!path.mkdirs()) {
        throw new IOException("Could not mkdirs " + path.getAbsolutePath());
return path;