Create and write to Files in Java - Java tutorial - w3Schools - Chapter-52 English

Published: 31 July 2022
on channel: w3Schools Tutorials
479
3

To create a file in Java, we can use the createNewFile() method. This method returns a boolean value: true if the file was successfully created, and false if the file already exists. Note that the method is enclosed in a try...catch block. This is necessary because it throws an IOException if an error occurs (if the file cannot be created for some reason).

We use the FileWriter class together with its write() method to write some text to the file . Note that when we are done writing to the file, we should close it with the close() method.


On this page of the site you can watch the video online Create and write to Files in Java - Java tutorial - w3Schools - Chapter-52 English with a duration of hours minute second in good quality, which was uploaded by the user w3Schools Tutorials 31 July 2022, share the link with friends and acquaintances, this video has already been watched 479 times on youtube and it was liked by 3 viewers. Enjoy your viewing!