美文网首页
file.mkdirs 和mkdir的区别

file.mkdirs 和mkdir的区别

作者: ae12 | 来源:发表于2018-12-05 14:28 被阅读5次

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.

相关文章

网友评论

      本文标题:file.mkdirs 和mkdir的区别

      本文链接:https://www.haomeiwen.com/subject/oxzicqtx.html