Java Path check if one Path object starts with another Path object
import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path p1 = Paths.get("C:\\myData\\Main.java"); Path p2 = Paths.get("C:\\MyData\\main.java"); Path p3 = Paths.get("C:\\myData\\..\\myData\\Main.java"); boolean b1 = p1.startsWith(p2); System.out.println(b1);//from www . j a va2 s. c om boolean b2 = p1.startsWith(p3); System.out.println(b2); } }