Java Path get path name count

Description

Java Path get path name count

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);//from www.j a  v  a 2s.com

    int count = p1.getNameCount();
    System.out.println("Name count: " + count);

    Path p2 = Paths.get("C:/abc/def/zyx/Main.java");

    count = p2.getNameCount();
    System.out.println("Name count: " + count);


  }

}



PreviousNext

Related