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;
/*from   w  w  w . j av a  2 s.  c om*/
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.





















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService