Java Utililty Methods Directory Create

List of utility methods to do Directory Create

Description

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

Method

voidmkdir(File file)
mkdir
if (file.exists()) {
    return;
File pFile = file.getParentFile();
if (pFile != null) {
    mkdir(pFile);
file.mkdir();
...
Filemkdir(File parent, String... segments)
mkdir
File dir = parent;
for (String segment : segments) {
    dir = new File(dir, segment);
dir.mkdirs();
return dir;
Filemkdir(File parentDir, String name)
mkdir
final File directory = new File(parentDir, name);
if (!directory.mkdir()) {
    throw new IOException();
return directory;
booleanmkdirs(File dir)
Creates a directory if the directory doesn't exists.
return dir.isDirectory() || dir.mkdirs() || dir.isDirectory();
voidmkdirs(File dir)
mkdirs
if (dir.exists()) {
    if (!dir.isDirectory()) {
        throw new IOException(
                "Failed to create directory '" + dir + "', regular file already existed with that name");
} else {
    if (!dir.mkdirs()) {
        throw new IOException("Failed to create directory '" + dir + "'");
...
Filemkdirs(File dir)
Ensures that the given directory exists (if not, it's created, including all the parent directories.)
if (dir.mkdirs() || dir.exists())
    return dir;
try {
    Thread.sleep(10);
} catch (InterruptedException e) {
if (dir.mkdirs() || dir.exists())
    return dir;
...
booleanmkdirs(File dir)
mkdirs
assert dir != null;
return dir.mkdirs() || dir.exists();
voidmkdirs(File dir)
create specified directory if doesn't exist.
if (!dir.exists() && !dir.mkdirs())
    throw new IOException("couldn't create directory: " + dir);
booleanmkdirs(File dir)
Mkdirs.
synchronized (mkdirsMutex) {
    try {
        mkdirsThread = Thread.currentThread();
        mkdirsStartTime = System.currentTimeMillis();
        return dir.mkdirs();
    } finally {
        mkdirsThread = null;
voidmkdirs(File dir)
Create directories, throw exception if not possible.
if (!dir.exists()) {
    if (!dir.mkdirs()) {
        throw new RuntimeException("Could not create directory : " + dir.getParentFile());
    return;
if (!dir.isDirectory()) {
    throw new RuntimeException("Should be a directory but is not: " + dir);
...