首页javapathJava I/O - 如何从Path对象获取文件名

Java I/O - 如何从Path对象获取文件名

我们想知道如何从Path对象获取文件名。
import java.nio.file.FileSystems;
import java.nio.file.Path;

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());
  }
}