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.





















Home »
  Java Tutorial »
    I/O »




Binary File
Byte Array
CharSet
Checksum
Console
Create Copy Move Delete
Directory
Drive
Encode Decode
File Attribute
File Lock
File System
GZIP
Jar File
NIO Buffer
Path
Scanner
StreamTokenizer
Temporary File
Text File
Zip