java.io.file 中mkdir和mkdirs的区别

  • mkdir
    public boolean mkdir()
    Creates the directory named by this abstract pathname.
    Returns:
    true if and only if the directory was created;  false otherwise
    Throws:
    SecurityException - If a security manager exists and its  SecurityManager.checkWrite(java.lang.String) method does not permit the named directory to be create
    为这个抽象目录创建目录结构。创建成功返回true,否则返回false。
    抛出安全异常

  • mkdirs
    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
    Throws:
    SecurityException - If a security manager exists and its  SecurityManager.checkRead(java.lang.String) method does not permit verification of the existence of the named directory and all necessary parent directories; or if the SecurityManager.checkWrite(java.lang.String) method does not permit the named directory and all necessary parent directories to be created
    根据抽象路径名 创建目录结构,包括必要但是不存在的父目录。请注意,如果操作失败,但它可能成功的创建了一些必要的父目录。
    如果目录被创建成功返回true,否则返回false。

    也就是意味着当目录结构不存在的时候 ”mkdir“ 是不能创建目录结构的,而 “mkdirs” 是可以帮助你创建不存在的目录结构的。但是有个缺点,如果程序报错终止,mkdirs有可能已经为你创建了目录结构。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值