Java I/O How to - Get the file name from the Path object


We would like to know how to get the file name from the Path object.


import java.nio.file.FileSystems;
import java.nio.file.Path;
//www. j  a v a  2  s  .co  m
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.