File Creation
File Creation
Java allows us to handle files and perform operations like create, read, write, update, and delete. This is known as File Handling in java. The java.io package has all the classes you will require to perform input and output (I/O) in Java. For this tutorial we will be using File class from the java.io package.
A. Create a File:
The createNewFile() method is used to create new files in java. This method throws an IOException if any error occurs.
Hence it is important to write it in a try…….catch block.
Example:
Output:
If we re-run the same code again, we get the following message: