Compare paths by using the compareTo() method, which compares two abstract paths lexicographically. - Java File Path IO

Java examples for File Path IO:Path

Description

Compare paths by using the compareTo() method, which compares two abstract paths lexicographically.

Demo Code

import java.nio.file.Path;
import java.nio.file.Paths;

public class Main {
  public static void main(String[] args) {
    Path path01 = Paths.get("/folder1/folder2/folder3/test.txt");
    Path path02 = Paths.get("C:/folder1/folder2/folder3/test.txt");

    //compare using Path.compareTo
    int compare = path01.compareTo(path02);
    System.out.println(compare);//  w  w  w. j  ava2  s. c  o  m

  }
}

Result


Related Tutorials