Java Utililty Methods Directory Exist Check

List of utility methods to do Directory Exist Check

Description

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

Method

voidcheckDir(String dir, boolean mustExist)
check Dir
File file = new File(dir);
if ((mustExist && !file.exists()) || file.isFile()) {
    throw new IllegalStateException("must be dir");
voidcheckDirectory(String name, boolean createIfNonExistent)
Checks if a directory exists.
File f = new File(name);
if ((f.exists()) && (!f.isDirectory())) {
    throw new IOException("Directory " + name + "already exists but is not a directory");
if ((!f.exists() && (!createIfNonExistent))) {
    throw new IOException("Directory " + name + " does not exist");
if (!f.exists() && (createIfNonExistent)) {
...
booleancheckDirectoryExists(String path)
check Directory Exists
boolean exists;
File directory = new File(path);
exists = directory.exists() || directory.mkdirs();
return exists;
BooleancheckDirExist(String path)
check Dir Exist
File file = new File(path);
if (!file.exists()) {
    file.mkdirs();
    System.out.println("Launcher.checkDirExist()#File doesn't exist, create new: " + path);
    return false;
return true;
voidcheckDirExistence(String dir)
check Dir Existence
File f = new File(dir);
if (!f.isDirectory()) {
    throw new RuntimeException("File: " + f + " is not a dir");
if (!f.exists()) {
    throw new RuntimeException("Dir: " + f + " does not exist");
voidcheckDirExistenceOrCreateMissingParts(final String dirPath)
check Dir Existence Or Create Missing Parts
final File dirFile = new File(dirPath);
if (!dirFile.exists()) {
    dirFile.mkdirs();
booleancheckDirExists(File dir)
check Dir Exists
if (dir.isDirectory()) {
    return true;
} else {
    return dir.mkdirs();
booleancheckDirExists(String dir)
check Dir Exists
File file = new File(dir);
return file.isDirectory();
voidCheckDirExists(String dir, String name)
Check Dir Exists
File dirFile = new File(dir);
if (!dirFile.exists()) {
    throw new IllegalArgumentException(
            "GDAJythonInterpreter.CheckDirExists: " + name + " - " + dir + " does not exist");