Path.getName(int index) has the following syntax.
Path getName(int index)
In the following code shows how to use Path.getName(int index) method.
//from w w w . j a v a2 s .co m import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String[] args) { Path path = Paths.get("C:", "tutorial/Java/JavaFX", "Topic.txt"); for (int i = 0; i < path.getNameCount(); i++) { System.out.println("Name element " + i + " is: " + path.getName(i)); } } }
The code above generates the following result.