比较两个路径的几种方式

来源:互联网 发布:网页视频提取软件 编辑:程序博客网 时间:2024/05/22 03:18
  • 定义基本路径
    //定义基本路径Path path01 = Paths.get("/cn/icer/ws/client/Business.java");Path path02 = Paths.get("F:/cn/icer/ws/client/Business.java");

  • Equal
    //First Methodif (path01.equals(path02)) {System.out.println("The paths are equal!");} else {System.out.println("The paths are not equals!");}

  • isSameFile
    //Second Methodtry {boolean check = Files.isSameFile(path01, path02);if (check) {System.out.println("The paths locate the same file!");} else {System.out.println("The paths does not locate the same file!");}} catch (Exception e) {e.printStackTrace();}

  • compateTo
    //Third Methodint compare = path01.compareTo(path02);System.out.println(compare);

  • startsWith and endsWith
    //Fourth Methodboolean sw = path01.startsWith("/cn/icer/ws/client");System.out.println(sw);boolean ew = path01.endsWith("Business.java");System.out.println(ew);


0 0
原创粉丝点击