Java IO Tutorial - Java Path.getFileName()








Syntax

Path.getFileName() has the following syntax.

Path getFileName()

Example

In the following code shows how to use Path.getFileName() method.

import java.nio.file.Path;
import java.nio.file.Paths;
//  www .  jav  a 2 s . com
public class Main {

  public static void main(String[] args) {

    Path path = Paths.get("C:", "tutorial/Java/JavaFX", "Topic.txt");

    System.out.println(path.getFileName());

  }
}

The code above generates the following result.