java.io.File的java中mkdir()和mkdirs()的区别 [英] Difference between mkdir() and mkdirs() in java for java.io.File

查看:33
本文介绍了java.io.File的java中mkdir()和mkdirs()的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我这两种方法的区别:

Can anyone tell me the difference between these two methods:

  • file.mkdir()
  • file.mkdirs()

推荐答案

mkdirs() 也在这个File的路径中创建父目录代表.

mkdirs() also creates parent directories in the path this File represents.

javadocs 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.

javadocs mkdir():

创建以此抽象路径名命名的目录.

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 [并且不会创建目录],并且为第二个产生 true,并且您将创建 non_existing_dir/someDir

will yield false for the first [and no dir will be created], and true for the second, and you will have created non_existing_dir/someDir

这篇关于java.io.File的java中mkdir()和mkdirs()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆