cn.hutool.core.io.FileUtil.mkParentDirs()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(2.1k)|赞(0)|评价(0)|浏览(713)

本文整理了Java中cn.hutool.core.io.FileUtil.mkParentDirs()方法的一些代码示例,展示了FileUtil.mkParentDirs()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.mkParentDirs()方法的具体详情如下:
包路径:cn.hutool.core.io.FileUtil
类名称:FileUtil
方法名:mkParentDirs

FileUtil.mkParentDirs介绍

[英]创建所给文件或目录的父目录
[中]创建所给文件或目录的父目录

代码示例

代码示例来源:origin: looly/hutool

/**
 * 创建父文件夹,如果存在直接返回此文件夹
 * 
 * @param path 文件夹路径,使用POSIX格式,无论哪个平台
 * @return 创建的目录
 */
public static File mkParentDirs(String path) {
  if (path == null) {
    return null;
  }
  return mkParentDirs(file(path));
}

代码示例来源:origin: looly/hutool

/**
 * 创建父文件夹,如果存在直接返回此文件夹
 * 
 * @param path 文件夹路径,使用POSIX格式,无论哪个平台
 * @return 创建的目录
 */
public static File mkParentDirs(String path) {
  if (path == null) {
    return null;
  }
  return mkParentDirs(file(path));
}

代码示例来源:origin: looly/hutool

/**
 * 创建文件及其父目录,如果这个文件存在,直接返回这个文件<br>
 * 此方法不对File对象类型做判断,如果File不存在,无法判断其类型
 * 
 * @param file 文件对象
 * @return 文件,若路径为null,返回null
 * @throws IORuntimeException IO异常
 */
public static File touch(File file) throws IORuntimeException {
  if (null == file) {
    return null;
  }
  if (false == file.exists()) {
    mkParentDirs(file);
    try {
      file.createNewFile();
    } catch (Exception e) {
      throw new IORuntimeException(e);
    }
  }
  return file;
}

代码示例来源:origin: looly/hutool

/**
 * 创建文件及其父目录,如果这个文件存在,直接返回这个文件<br>
 * 此方法不对File对象类型做判断,如果File不存在,无法判断其类型
 * 
 * @param file 文件对象
 * @return 文件,若路径为null,返回null
 * @throws IORuntimeException IO异常
 */
public static File touch(File file) throws IORuntimeException {
  if (null == file) {
    return null;
  }
  if (false == file.exists()) {
    mkParentDirs(file);
    try {
      file.createNewFile();
    } catch (Exception e) {
      throw new IORuntimeException(e);
    }
  }
  return file;
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 创建父文件夹,如果存在直接返回此文件夹
 * 
 * @param path 文件夹路径,使用POSIX格式,无论哪个平台
 * @return 创建的目录
 */
public static File mkParentDirs(String path) {
  if (path == null) {
    return null;
  }
  return mkParentDirs(file(path));
}

代码示例来源:origin: cn.hutool/hutool-all

/**
 * 创建文件及其父目录,如果这个文件存在,直接返回这个文件<br>
 * 此方法不对File对象类型做判断,如果File不存在,无法判断其类型
 * 
 * @param file 文件对象
 * @return 文件,若路径为null,返回null
 * @throws IORuntimeException IO异常
 */
public static File touch(File file) throws IORuntimeException {
  if (null == file) {
    return null;
  }
  if (false == file.exists()) {
    mkParentDirs(file);
    try {
      file.createNewFile();
    } catch (Exception e) {
      throw new IORuntimeException(e);
    }
  }
  return file;
}

相关文章

微信公众号

最新文章

更多