Can anyone tell me the difference between these two methods:
mkdirs() also creates parent directories in the path this
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.
Creates the directory named by this abstract pathname.
File f = new File("non_existing_dir/someDir"); System.out.println(f.mkdir()); System.out.println(f.mkdirs());
false for the first [and no dir will be created], and
true for the second, and you will have created
mkdirs() will create the specified directory path in its entirety where
mkdir() will only create the bottom most directory, failing if it can’t find the parent directory of the directory it is trying to create.
In other words
mkdir() is like
mkdirs() is like
For example, imagine we have an empty
/tmp directory. The following code
would create the following directories:
Where this code:
would not create any directories – as it wouldn’t find
/tmp/one/two – and would return
creates only one directory at a time, if it is parent that one only. other wise it can create the sub directory(if the specified path is existed only) and do not create any directories in between any two directories. so it can not create smultiple directories in one directory
create the multiple directories(in between two directories also) at a time.