Writing Files in Java (with examples)
The createNewFile() function in Java can create a file. This method produces a boolean value: true if the file was completed successfully, false if it already exists. As you can see, the procedure is encased in a try…catch block. It is required because an IOException is thrown if an error occurs. For example, if the file cannot be created for any reason.