Java NIO2 – Path, Paths and Files

Java NIO2 – Path, Paths and Files
In this article we are going to see java.nio package – Path, Paths and Files.

First let us understand these terms,

Path – This is an interface which replaces File
Paths – This contains methods to create path object
Files – Contains methods that work with Path object

Similar to files, We can perform operations like creating, deleting, moving and copying operations using Path too. We are going to see an example about how to create, copy, move and delete a file using Path.

Creating Path:

Path path = Paths.get(“directory”);

After using the above to create a directory, then we have to create the directory – Note that similar to files, Path just creates an object and does not create the directory/file. We have to declare createDirectory/createFile to create the directory or file.

Now let us see an example,

op1

Leave a Reply

Your email address will not be published. Required fields are marked *