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.
Methods
|
Method |
Description |
|
|
Copies the source file to the target file. |
|
|
Moves or renames the source file to the target path and deletes the original file. |
|
|
Creates a directory. All directories in the path up to the directory that the new directory is to be created within must already exist. |
|
|
Creates a new directory, including any intermediate directories in the path. |
|
|
Creates a file. |
|
|
Deletes the file or directory. The method throws an exception if the file or directory doesn’t exist or couldn’t be deleted. |
|
|
Deletes the file or directory if it exists. The method doesn’t throw an exception if the file or directory doesn’t exist. |
|
|
Returns |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access