mkdirs() return value for already existing directories
file, java, mkdirs
Solution
It returns false.
From java doc: - true if the directory was created, false on failure or if the directory already existed.
You should do something like this:
if (file.mkdirs()) {
System.out.format("Directory %s has been created.", file.getAbsolutePath());
} else if (file.isDirectory()) {
System.out.format("Directory %s has already been created.", file.getAbsolutePath());
} else {
System.out.format("Directory %s could not be created.", file.getAbsolutePath());
}
Problem
File.mkdirs JavaDocs: public boolean mkdirs() Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories. Returns: true if and only if the directory was created, along with all necessary parent directories; false otherwise My question is: Does mkdirs() return false if some of the directories it wanted to create already existed? Or does it just return true if it was successful in creating the entire path for the File, whether or not some directories already existed?