Paths Class

Package: java.nio.file

The Paths class provides a single method (get), which returns a Path object for a given file path string. For more information, see Path Interface.

Method

Method

Description

static Path get(String path)

Returns a path object for the specified path string.

Here’s an example that uses the get method of the static Paths class, like this:

Path p = Paths.get(“c:\\test.txt”);

Here, the file’s name is test.txt, and it resides in the root directory of the C: drive.

After it’s created by the get method, the Path object can be used with the Files class to manipulate the file or directory represented by the Path object. For more information, see Files Class.

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.