Java Path.getName(int index)
Syntax
Path.getName(int index) has the following syntax.
Path getName(int index)
Example
In the following code shows how to use Path.getName(int index) method.
// w ww . ja va 2 s .c o 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.