Get the number of name element in a Path object in Java
Description
The following code shows how to get the number of name element in a Path object.
Example
/* w ww .ja v a 2 s. c om*/
import java.nio.file.Path;
import java.nio.file.Paths;
public class Main {
public static void main(String[] args) throws Exception{
Path listing = Paths.get("/usr/bin/zip");
System.out.println("Number of Name Elements in the Path [" + listing.getNameCount() + "]");
}
}
The code above generates the following result.