Java Utililty Methods mkdir

List of utility methods to do mkdir

Description

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

Method

StringmakeDirectories(String path)
make Directories
try {
    File file = new File(path);
    file.mkdirs();
    return file.getCanonicalPath();
} catch (IOException e) {
    return null;
voidmakeDirectories(String path)
Create a directory structure
File target = new File(path);
if (target.exists()) {
    if (!target.isDirectory()) {
        throw new IOException("Target directory for generating CreativeWorks files is actually a file");
} else {
    target.mkdirs();
voidmakeDirectory(File dir)
make Directory
if (dir.exists()) {
    if (!dir.isDirectory()) {
        throw new IOException("File '" + dir + "' is already exist");
} else {
    if (!dir.mkdirs()) {
        throw new IOException("Cannot create directory '" + dir + "'");
voidmakeDirectory(File directory)
make Directory
if (!directory.exists() && !directory.mkdirs()) {
    throw new RuntimeException(String.format("Directory %s can not be created", directory));
voidmakeDirectory(File file)
Creates directories if not exists.
if (!file.isDirectory()) {
    if (!file.mkdirs() || !file.isDirectory()) {
        throw new IOException("can't make directory: " + file);
booleanmakeDirectory(File file)
make Directory
File parent = file.getParentFile();
return parent != null && parent.mkdirs();
booleanmakeDirectory(File file)
make Directory
return file.mkdirs();
voidmakedirectory(File outputDirectory, String directoryName)
Create a directory
File directory = new File(outputDirectory, directoryName);
if (!directory.exists()) {
    directory.mkdirs();
booleanmakeDirectory(File testDir )
Utility for making dirs
if (testDir == null) {
    return false;
if (testDir.isDirectory()) {
    return true;
return testDir.mkdirs();
FilemakeDirectory(final CharSequence aPath)
Returns a valid directory from the given path (it may return the parent directory).
final File directory = new File(aPath.toString());
if (!directory.exists()) {
    if (!directory.mkdirs()) {
        throw new IOException("Directory not created. Already existing ?");
} else if (!directory.isDirectory()) {
    throw new IOException("'" + aPath + "' is not a valid directory.");
return directory;