Java Path get path component name by index

Description

Java Path get path component name by index

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");

    System.out.println("getName 0: " + p.getName(0));
    System.out.println("getName 3: " + p.getName(3));
    System.out.println("getName 5: " + p.getName(5));
  }/*  w  ww .j  a  va2s  . c  o m*/
}



PreviousNext

Related