Java Path get path component one by one

Description

Java Path get path component one by one

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

    System.out.println(p1);/*w  ww.  j  ava2  s.  co  m*/

    int count = p1.getNameCount();
    for (int i = 0; i < count; i++) {
      Path name = p1.getName(i);
      System.out.println("Name at index " + i + " is " + name);
    }
  }
}



PreviousNext

Related