Java Path get sub path
import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path p = Paths.get("c:/a/b/c/d/e/Main.java"); Path p2 = p.subpath(0, 1);/* w w w. j a v a 2 s . c om*/ Path p3 = p.subpath(1, 2); Path p4 = p.subpath(0, 2); System.out.println(p2); System.out.println(p3); System.out.println(p4); } }