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 dir, boolean createDirectoryIfNotExisting)
mkdir
if (!dir.exists()) {
    if (!createDirectoryIfNotExisting) {
        throw new IOException("The directory " + dir.getAbsolutePath() + " does not exist.");
    if (!dir.mkdirs()) {
        throw new IOException("Could not create directory " + dir.getAbsolutePath());
if (!dir.isDirectory()) {
    throw new IOException("File " + dir + " exists and is not a directory. Unable to create directory.");
Filemkdir(File directory)
Makes a directory.
if (!directory.mkdir())
    throw new IOException("Unable to create directory: " + directory.getPath());
return directory;
booleanmkdir(File directory)
Create a new directory.
if (directory.exists()) {
    return false;
return directory.mkdir();
voidmkdir(File directory)
Creates the specified directory.
if (!directory.exists()) {
    boolean succeeded = directory.mkdirs();
    if (!succeeded) {
        throw new IllegalStateException(
                String.format("Error while creating directory: %s", directory.getAbsolutePath()));
voidmkdir(File dirFile)
Create a directory by calling mkdir();
try {
    boolean bFile = dirFile.exists();
    if (bFile == true) {
        System.err.println("The folder exists.");
    } else {
        System.err.println("The folder do not exist,now trying to create a one...");
        bFile = dirFile.mkdir();
        if (bFile == true) {
...
voidmkdir(File dirFile)
Create a directory by calling mkdir();
System.out.println("Creating the folder: " + dirFile);
try {
    boolean bFile = dirFile.exists();
    if (bFile == true) {
        System.out.println("The folder exists.");
    } else {
        System.out.println("The folder do not exist,now trying to create a one...");
        bFile = dirFile.mkdir();
...
voidmkdir(File f)
mkdir
if (!f.exists()) {
    f.mkdir();
voidmkdir(File f)
Same as File.mkdirs() exception IOException is thrown on error.
if (f.exists() && f.isDirectory())
    return;
if (!f.mkdirs())
    throw new IOException("Cannot mkdir: " + f);
voidmkDir(File file)
mk Dir
if (file.getParentFile().exists()) {
    file.mkdir();
} else {
    mkDir(file.getParentFile());
    file.mkdir();
booleanmkdir(File file)
mkdir
if (file.exists()) {
    assertIsDir(file);
    return false;
if (file.mkdirs())
    return true;
throw new RuntimeException("Failed to create directory '" + file + "'");