How to Create File in Java

In this post we will see an example on how we can create file in java.
We will use the File.createNewFile() method.

File.createNewFile() creates a new empty file if a file doesn’t exists already in the given path.

createNewFile() returns “true” if file is created successfully.
If we try to create a file that already exists in the given path then createNewFile() returns false.

Example : Create File in java

When performing any operation on File, you will need to handle the IOException exception.

You can get more details on the File API here