Get the file name from the Path object in Java
Description
The following code shows how to get the file name from the Path object.
Example
import java.nio.file.FileSystems;
import java.nio.file.Path;
// ww w.j a v a2 s.c om
public class Main {
public static void main(String[] args) {
Path path = FileSystems.getDefault().getPath("/home/docs/status.txt");
System.out.printf("getFileName: %s\n", path.getFileName());
}
}
The code above generates the following result.