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,


Saving Image in Folder and path in database using Java

Saving Image in Folder and path in database using Java

Here is the code to get the image from the user and store it in a folder and store the image path in Database.

JSP and Servlet
MySql Database
Tested with Netbeans 8.0

Database – create table with name and photourl as fields with datatype varchar().

JSP: (Upload Image)