files - Selecting Pieces of a Path

本文探讨了Java NIO中Path类的endsWith方法的工作原理,通过实例展示了如何判断路径是否以特定子路径结束,解释了该方法在不同情况下的行为。

java.nio.file, n now means "non-blocking" .

Path objects can easily yield parts of their path:

// files/PartsOfPaths.java
// (c)2017 MindView LLC: see Copyright.txt
// We make no guarantees that this code is fit for any purpose.
// Visit http://OnJava8.com for more book information.

import java.nio.file.*;

public class PartsOfPaths {
  public static void main(String[] args) {
    System.out.println(System.getProperty("os.name"));
    Path p = Paths.get("PartsOfPaths.java").toAbsolutePath();
    System.out.println("p:" + p);
    for (int i = 0; i < p.getNameCount(); i++) {
      System.out.println(p.getName(i));
    }
    System.out.println("ends with '.java': " + p.endsWith(".java")); // false. [1]
    // p.endsWith("PartsOfPaths.java") produce true
    for (Path pp : p) {
      System.out.print(pp + ": ");
      System.out.print(p.startsWith(pp) + " : ");
      System.out.println(p.endsWith(pp));
    }
    System.out.println("Starts with " + p.getRoot() + " " + p.startsWith(p.getRoot()));
  }
}
/* My Output:
Mac OS X
p:/Users/wangbingfeng/github/OnJava8-Examples/files/PartsOfPaths.java
Users
wangbingfeng
github
OnJava8-Examples
files
PartsOfPaths.java
ends with '.java': false
Users: false : false
wangbingfeng: false : false
github: false : false
OnJava8-Examples: false : false
files: false : false
PartsOfPaths.java: false : true
Starts with / true
*/

Note that[1], even though my path here does end with .java, endsWith() produces false. This is because endsWith() is comparing the entire path component, not a substring within the name.

 

  • endsWith

    boolean endsWith(Path other)
    Tests if this path ends with the given path.

    If the given path has N elements, and no root component, and this path has N or more elements, then this path ends with the given path if the last N elements of each path, starting at the element farthest from the root, are equal.

    If the given path has a root component then this path ends with the given path if the root component of this path ends with the root component of the given path, and the corresponding elements of both paths are equal. Whether or not the root component of this path ends with the root component of the given path is file system specific. If this path does not have a root component and the given path has a root component then this path does not end with the given path.

    If the given path is associated with a different FileSystem to this path then false is returned.

    Parameters:

    other - the given path

    Returns:

    true if this path ends with the given path; otherwise false

  • endsWith

    boolean endsWith(String other)

    Tests if this path ends with a Path, constructed by converting the given path string, in exactly the manner specified by the endsWith(Path) method. On UNIX for example, the path "foo/bar" ends with "foo/bar" and "bar". It does not end with "r" or "/bar". Note that trailing separators are not taken into account, and so invoking this method on the Path"foo/bar" with the String "bar/" returns true.

    Parameters:

    other - the given path string

    Returns:

    true if this path ends with the given path; otherwise false

    Throws:

    InvalidPathException - If the path string cannot be converted to a Path.

references:

1. On Java 8 - Bruce Eckel

2. https://github.com/wangbingfeng/OnJava8-Examples/blob/master/files/PartsOfPaths.java

3. https://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html#endsWith-java.lang.String-

本系统旨在构建一套面向高等院校的综合性教务管理平台,涵盖学生、教师及教务处三个核心角色的业务需求。系统设计着重于实现教学流程的规范化与数据处理的自动化,以提升日常教学管理工作的效率与准确性。 在面向学生的功能模块中,系统提供了课程选修服务,学生可依据培养方案选择相应课程,并生成个人专属的课表。成绩查询功能支持学生查阅个人各科目成绩,同时系统可自动计算并展示该课程的全班最高分、平均分、最低分以及学生在班级内的成绩排名。 教师端功能主要围绕课程与成绩管理展开。教师可发起课程设置申请,提交包括课程编码、课程名称、学分学时、课程概述在内的新课程信息,亦可对已开设课程的信息进行更新或撤销。在课程管理方面,教师具备录入所授课程期末考试成绩的权限,并可导出选修该课程的学生名单。 教务处作为管理中枢,拥有课程审批与教学统筹两大核心职能。课程设置审批模块负责处理教师提交的课程申请,管理员可根据教学计划与资源情况进行审核批复。教学安排模块则负责全局管控,包括管理所有学生的选课最终结果、生成包含学号、姓名、课程及成绩的正式成绩单,并能基于选课与成绩数据,统计各门课程的实际选课人数、最高分、最低分、平均分以及成绩合格的学生数量。 资源来源于网络分享,仅用于学习交流使用,请勿用于商业,如有侵权请联系我删除!
<think>好的,用户想知道为什么在ACPI开发中选择'acpica-tools'而不是'iasl',以及它们的区别。首先,我需要确认这两个工具的关系和各自的功能。 记得之前了解过,ACPI相关工具有IASL(Intel ASL编译器),它主要用于编译ASL代码到AML。而acpica-tools可能是一个工具集,包含IASL和其他工具。需要验证这一点。 查找资料发现,acpica-tools是ACPICA项目提供的工具集合,包括iasl编译器以及其他实用程序,比如acpiexec、acpidump等。而单独的iasl可能只是其中的编译器部分。因此,选择acpica-tools可能是因为需要更全面的工具支持,而不仅仅是编译功能。 另外,用户可能在开发过程中需要调试、反编译或分析ACPI表,这时候acpica-tools提供的其他工具就显得必要了。比如,acpiexec用于模拟执行AML代码,acpidump用于提取系统ACPI表,这些在单独使用iasl时可能无法实现。 还需要考虑不同Linux发行版的软件包管理情况。例如,在Debian/Ubuntu中,安装acpica-tools会包含iasl,而单独安装iasl可能版本较旧或者功能不全。因此,推荐使用acpica-tools以获得最新和全面的工具支持。 总结一下,区别在于acpica-tools是一个综合工具包,而iasl是其中的编译器。选择前者可以提供更完整的开发环境,适合需要多种工具配合的场景。而如果仅需编译ASL代码,单独使用iasl可能足够。</think>在ACPI开发中选择`acpica-tools`还是`iasl`,主要取决于开发需求和工作流程。以下是两者的区别与选择建议: ### 1. **工具定位与功能范围** - **`iasl`** 是Intel ACPI编译器(Intel ACPI Source Language Compiler)的独立版本,核心功能是将ASL(ACPI Source Language)代码编译为AML(ACPI Machine Language)字节码。它是ACPI开发中**最基础的编译工具**,适用于仅需完成源码到二进制转换的场景。 - **`acpica-tools`** 是ACPICA项目提供的**完整工具套件**,包含以下组件: - `iasl`:编译器(支持ASL到AML的编译和AML反编译为ASL) - `acpiexec`:AML模拟执行器,用于调试ACPI代码 - `acpidump`:提取系统ACPI表的工具 - `acpixtract`:从系统转储中分离单个ACPI表 因此,`acpica-tools`不仅覆盖编译需求,还提供**调试、分析和逆向工程**的支持[^2][^3]。 ### 2. **版本更新与兼容性** - **`iasl`独立版本** 可能滞后于ACPICA项目的主线更新,尤其是通过Linux发行版仓库安装时(如`apt install iasl`)。例如,Ubuntu 22.04默认仓库的`iasl`版本为20200925,而截至2023年ACPICA已更新至20230628。**旧版本可能缺少对新语法或ACPI规范的支持**。 - **`acpica-tools`** 通过官方渠道(如ACPICA官网或GitHub)获取时,通常包含最新功能和对ACPI 6.x规范的完整支持,适合需要**兼容最新硬件或调试复杂ACPI行为**的场景[^1]。 ### 3. **典型使用场景** - **选择`iasl`的场合** - 仅需快速编译ASL代码(如修改DSDT/SSDT表) - 嵌入式环境中资源受限,需最小化工具体积 - **选择`acpica-tools`的场合** - 需要**调试AML代码**(如通过`acpiexec`模拟执行并跟踪ACPI方法) - 需要**逆向分析**系统ACPI表(如使用`acpidump`提取表后,用`iasl -d`反编译为ASL) - 需要验证ACPI代码是否符合规范(如通过`acpihelp`查询ACPI对象定义) ### 4. **安装与使用示例** - **安装`acpica-tools`(推荐方式)** ```bash # Debian/Ubuntu sudo apt install acpica-tools # 或从源码编译最
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值