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

booleanmkdirs(String path, boolean override)
mkdirs
boolean _flag = false;
File _path = new File(path);
if (!_path.exists()) {
    _path.mkdirs();
    _flag = true;
} else {
    if (override) {
        _flag = true;
...
booleanmkdirs(String s)
Mkdirs.
File f = new File(s);
return f.mkdirs();
voidmkdirsFor(File destination)
mkdirs For
if (destination.getParentFile() != null && !destination.getParentFile().exists()) {
    destination.getParentFile().mkdirs();
booleanmkdirsIfAbsent(String pathname)
Make Directories (including parent directories) if not exist.
File file = new File(pathname);
if (!file.exists()) {
    return file.mkdirs();
return true;
booleanmkdirsIfNotExists(String pathname)
mkdirs If Not Exists
File file = new File(pathname);
if (!file.isDirectory()) {
    if (!file.mkdirs()) {
        System.err.println("fail to create directory: " + pathname);
        return false;
return true;
...
voidmkdirsifnotExists(String s)
Mkdirsifnot exists.
if (s == null) {
    return;
File f = new File(s);
if (!f.exists()) {
    f.mkdirs();
voidmkdirsInRemote(String host, String path, boolean deleteIfExisted)
mkdirs In Remote
if (deleteIfExisted)
    deleteInRemote(host, path);
if (!runCommandInRemoteHost(host, "mkdir -p " + path, 0).isEmpty())
    throw new IOException("fail to delete " + host + ":" + path);
voidmkdirsOrCrash(File d)
mkdirs Or Crash
if (!d.exists())
    d.mkdirs();
if (!d.isDirectory())
    throw new RuntimeException("\"" + d.getAbsolutePath() + "\" must be a directory. Aborting.");
voidmkdirsOrFail(File dirFile)
Check if given file is directory and try to create it if not.
if (dirFile == null) {
    return;
if (!dirFile.isDirectory()) {
    if (!dirFile.mkdirs()) {
        throw new IOException(
                "Directory doesn't exist and its creation failed: " + dirFile.getAbsolutePath());
booleanmkdirsWithExistsCheck(File dir)
mkdirs With Exists Check
if (dir.mkdir() || dir.exists()) {
    return true;
File canonDir = null;
try {
    canonDir = dir.getCanonicalFile();
} catch (IOException e) {
    return false;
...