Files Class

Package: java.nio.file

The Files class consists entirely of static methods that can perform operations on files, which are represented by Path objects. For example, to delete a file, you first get a Path object that points to the file. Then, you pass the Path object to the delete method of the Files class to delete the file.

CrossRef.eps For more information, see Path Class.




static Path copy(Path source, Path target)

Copies the source file to the target file.

static Path move(Path source, Path target)

Moves or renames the source file to the target path and deletes the original file.

static Path create Directory(Path dir)

Creates a directory. All directories in the path up to the directory that the new directory is to be created within must already exist.

static Path create Directories(Path dir)

Creates a new directory, including any intermediate directories in the path.

static Path createFile(Path file)

Creates a file.

static void delete (Path path)

Deletes the file or directory. The method throws an exception if the file or directory doesn’t exist or couldn’t be deleted.

static void delete IfExists(Path path)

Deletes the file or directory if it exists. The method doesn’t throw an exception if the file or directory doesn’t exist.

static boolean exists(Path path)

Returns true if the file exists ...

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.