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

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

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

FileUtil.isAbsolutePath介绍

[英]给定路径已经是绝对路径
此方法并没有针对路径做标准化,建议先执行 #normalize(String)方法标准化路径后判断
[中]给定路径已经是绝对路径
此方法并没有针对路径做标准化,建议先执行 #规范化(字符串)方法标准化路径后判断

代码示例

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

/**
   * 获取{@link Resource} 资源对象<br>
   * 如果提供路径为绝对路径,返回{@link FileResource},否则返回{@link ClassPathResource}
   * 
   * @param path 路径,可以是绝对路径,也可以是相对路径
   * @return {@link Resource} 资源对象
   * @since 3.2.1
   */
  public static Resource getResourceObj(String path) {
    return FileUtil.isAbsolutePath(path) ? new FileResource(path) : new ClassPathResource(path);
  }
}

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

/**
   * 获取{@link Resource} 资源对象<br>
   * 如果提供路径为绝对路径,返回{@link FileResource},否则返回{@link ClassPathResource}
   * 
   * @param path 路径,可以是绝对路径,也可以是相对路径
   * @return {@link Resource} 资源对象
   * @since 3.2.1
   */
  public static Resource getResourceObj(String path) {
    return FileUtil.isAbsolutePath(path) ? new FileResource(path) : new ClassPathResource(path);
  }
}

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

/**
 * 获得绝对路径Path<br>
 * 对于不存在的资源,返回拼接后的绝对路径
 * 
 * @return 绝对路径path
 */
public final String getAbsolutePath() {
  if (FileUtil.isAbsolutePath(this.path)) {
    return this.path;
  }
  // url在初始化的时候已经断言,此处始终不为null
  return FileUtil.normalize(URLUtil.getDecodedPath(this.url));
}

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

/**
 * 获得绝对路径Path<br>
 * 对于不存在的资源,返回拼接后的绝对路径
 * 
 * @return 绝对路径path
 */
public final String getAbsolutePath() {
  if (FileUtil.isAbsolutePath(this.path)) {
    return this.path;
  }
  // url在初始化的时候已经断言,此处始终不为null
  return FileUtil.normalize(URLUtil.getDecodedPath(this.url));
}

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

/**
   * 标准化Path格式
   * 
   * @param path Path
   * @return 标准化后的path
   */
  private String normalizePath(String path) {
    // 标准化路径
    path = FileUtil.normalize(path);
    path = StrUtil.removePrefix(path, StrUtil.SLASH);

    Assert.isFalse(FileUtil.isAbsolutePath(path), "Path [{}] must be a relative path !", path);
    return path;
  }
}

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

/**
   * 标准化Path格式
   * 
   * @param path Path
   * @return 标准化后的path
   */
  private String normalizePath(String path) {
    // 标准化路径
    path = FileUtil.normalize(path);
    path = StrUtil.removePrefix(path, StrUtil.SLASH);

    Assert.isFalse(FileUtil.isAbsolutePath(path), "Path [{}] must be a relative path !", path);
    return path;
  }
}

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

/**
 * 渲染模板,如果为相对路径,则渲染ClassPath模板,否则渲染本地文件模板
 * 
 * @param path 路径
 * @param templateFileName 模板文件名
 * @param bindingMap 绑定参数
 * @return 渲染后的内容
 * @since 3.2.0
 */
public static String render(String path, String templateFileName, Map<String, Object> bindingMap) {
  if (FileUtil.isAbsolutePath(path)) {
    return render(getFileTemplate(path, templateFileName), bindingMap);
  } else {
    return render(getClassPathTemplate(path, templateFileName), bindingMap);
  }
}

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

/**
 * 渲染模板,如果为相对路径,则渲染ClassPath模板,否则渲染本地文件模板
 * 
 * @param path 路径
 * @param templateFileName 模板文件名
 * @param bindingMap 绑定参数
 * @return 渲染后的内容
 * @since 3.2.0
 */
public static String render(String path, String templateFileName, Map<String, Object> bindingMap) {
  if (FileUtil.isAbsolutePath(path)) {
    return render(getFileTemplate(path, templateFileName), bindingMap);
  } else {
    return render(getClassPathTemplate(path, templateFileName), bindingMap);
  }
}

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

} else {
  normalPath = normalize(path);
  if (isAbsolutePath(normalPath)) {

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

} else {
  normalPath = normalize(path);
  if (isAbsolutePath(normalPath)) {

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

/**
   * 获取{@link Resource} 资源对象<br>
   * 如果提供路径为绝对路径,返回{@link FileResource},否则返回{@link ClassPathResource}
   * 
   * @param path 路径,可以是绝对路径,也可以是相对路径
   * @return {@link Resource} 资源对象
   * @since 3.2.1
   */
  public static Resource getResourceObj(String path) {
    return FileUtil.isAbsolutePath(path) ? new FileResource(path) : new ClassPathResource(path);
  }
}

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

/**
 * 获得绝对路径Path<br>
 * 对于不存在的资源,返回拼接后的绝对路径
 * 
 * @return 绝对路径path
 */
public final String getAbsolutePath() {
  if (FileUtil.isAbsolutePath(this.path)) {
    return this.path;
  }
  // url在初始化的时候已经断言,此处始终不为null
  return FileUtil.normalize(URLUtil.getDecodedPath(this.url));
}

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

/**
   * 标准化Path格式
   * 
   * @param path Path
   * @return 标准化后的path
   */
  private String normalizePath(String path) {
    // 标准化路径
    path = FileUtil.normalize(path);
    path = StrUtil.removePrefix(path, StrUtil.SLASH);

    Assert.isFalse(FileUtil.isAbsolutePath(path), "Path [{}] must be a relative path !", path);
    return path;
  }
}

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

/**
 * 渲染模板,如果为相对路径,则渲染ClassPath模板,否则渲染本地文件模板
 * 
 * @param path 路径
 * @param templateFileName 模板文件名
 * @param bindingMap 绑定参数
 * @return 渲染后的内容
 * @since 3.2.0
 */
public static String render(String path, String templateFileName, Map<String, Object> bindingMap) {
  if (FileUtil.isAbsolutePath(path)) {
    return render(getFileTemplate(path, templateFileName), bindingMap);
  } else {
    return render(getClassPathTemplate(path, templateFileName), bindingMap);
  }
}

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

} else {
  normalPath = normalize(path);
  if (isAbsolutePath(normalPath)) {

相关文章

微信公众号

最新文章

更多