mkdirs:会一步到位创建目录文件(即使目录不存在);
mkdir:如果找不到上一级的目录,会创建失败
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 mkdir and mkdirs() is like mkdir -p.
For example, imagine we have an empty /tmp directory. The following code
代码块
new File("/tmp/one/two/three").mkdirs();
would create the following directories:
/tmp/one
/tmp/one/two
/tmp/one/two/three
Where this code:
new File("/tmp/one/two/three").mkdir();
would not create any directories - as it wouldn't find /tmp/one/two - and would return false.
网友评论