Path Interface

Package: java.nio.file

The Path interface defines an object that represents a file or directory path. Note that a Path object doesn’t represent the file or directory indicated by the path; it represents the path to the file. The file or directory pointed to by a Path object may or may not actually exist on disk.

Because Path is an interface, not a class, it has no constructors. Of the many ways to create a Path object, one of the most common is to use the get method of the Paths class. For more information, see Paths Class.

Path objects can also be created by static members of the Files class. For more information, see Files Class.

Remember.eps Yes, it’s confusing that there is an interface named Path and a class named Paths, and separate classes named File and Files. At times, it seems like “Confusing” is Java’s middle name.

A Path object can be thought of as a root component and a hierarchical sequence of distinct names separated by separator characters (usually backslashes). The root component identifies the file system being used; in a Windows system, this might be a drive letter. The sequence of names represents the directories needed to navigate through the file system to the target file or directory. The last name in the sequence represents the name of the target file or directory itself.

Methods

Method

Description

Path getFileName()

Returns the name of the ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.