Android 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

voidcreateIfDoesntExist(File dir, boolean mustBeReadable, boolean mustBeWritable)
creates a directory if it doesnt exist and verifies permissions
if (dir.exists()) {
    if (!dir.isDirectory())
        throw new IOException(dir.getAbsolutePath()
                + " exists but isn't a directory");
} else {
    if (!dir.mkdirs())
        throw new IOException("Couldn't create directory "
                + dir.getAbsolutePath());
...
booleancreateMissingParentDirectories(File file)
create Missing Parent Directories
File parent = file.getParentFile();
if (parent == null) {
    throw new IllegalStateException(file
            + " should not have a null parent");
if (parent.exists()) {
    throw new IllegalStateException(file
            + " should not have existing parent directory");
...
FilecreateNewDirectory(String directorPath)
create New Directory
File dir = new File(directorPath);
if (dir.exists())
    return dir;
dir.mkdirs();
return dir;
FilecreateOrGetDir(String path, boolean mustBeReadable, boolean mustBeWritable)
Creates a directory or gets it if it exists.
File dir = new File(path);
createIfDoesntExist(dir, mustBeReadable, mustBeWritable);
return dir;
booleandirWritable(String dir)
dir Writable
return dirWritable(new File(dir));
Filedirectory(File base, String dir)
Returns the File for a named directory.
return directory(base.getPath(), dir);
Filedirectory(File dir)
Returns the File for a directory.
if (!dir.exists()) {
    if (!dir.mkdirs()) {
        throw new IOException(Fmt.S("can't create directory %s",
                dir));
if (!dir.isDirectory()) {
    throw new IOException(Fmt.S("%s is not a directory", dir));
...
Filedirectory(String base, String dir)
Returns the File for a named directory.
return directory(new File(new File(base), dir));
Filedirectory(String dir)
Returns the File for a named directory.
return directory(new File(dir));
voidensureDirectoryExist(File dir)
ensure Directory Exist
if (!dir.exists()) {
    boolean success = dir.mkdirs();
    if (!success)
        throw new IOException("Cannot create directory");
} else {
    if (!dir.isDirectory())
        throw new IOException(dir.getName() + " is not a directory");