jodd.io.FileUtil.getParentFile()方法的使用及代码示例

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

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

FileUtil.getParentFile介绍

[英]Returns parent for the file. The method correctly processes "." and ".." in file names. The name remains relative if was relative before. Returns null if the file has no parent.
[中]返回文件的父级。该方法正确处理“”和“.”在文件名中。如果名称以前是相对的,则名称仍然是相对的。如果文件没有父级,则返回null

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Check if one file is an ancestor of second one.
 *
 * @param strict   if <code>false</code> then this method returns <code>true</code> if ancestor
 *                 and file are equal
 * @return <code>true</code> if ancestor is parent of file; <code>false</code> otherwise
 */
public static boolean isAncestor(File ancestor, File file, boolean strict) {
  File parent = strict ? getParentFile(file) : file;
  while (true) {
    if (parent == null) {
      return false;
    }
    if (parent.equals(ancestor)) {
      return true;
    }
    parent = getParentFile(parent);
  }
}

代码示例来源:origin: oblac/jodd

/**
 * Check if one {@link File} is an ancestor of second one.
 *
 * @param strict if c then this method returns {@code true} if ancestor
 *               and {@link File} are equal
 * @return {@code true} if ancestor is parent of {@link File}; otherwise, {@code false}
 */
public static boolean isAncestor(final File ancestor, final File file, final boolean strict) {
  File parent = strict ? getParentFile(file) : file;
  while (true) {
    if (parent == null) {
      return false;
    }
    if (parent.equals(ancestor)) {
      return true;
    }
    parent = getParentFile(parent);
  }
}

代码示例来源:origin: org.jodd/jodd-core

/**
 * Check if one {@link File} is an ancestor of second one.
 *
 * @param strict if c then this method returns {@code true} if ancestor
 *               and {@link File} are equal
 * @return {@code true} if ancestor is parent of {@link File}; otherwise, {@code false}
 */
public static boolean isAncestor(final File ancestor, final File file, final boolean strict) {
  File parent = strict ? getParentFile(file) : file;
  while (true) {
    if (parent == null) {
      return false;
    }
    if (parent.equals(ancestor)) {
      return true;
    }
    parent = getParentFile(parent);
  }
}

相关文章

微信公众号

最新文章

更多