File handling is an important part of any application. So before we get to know how to read and write to a file in java, first we need to know how to create a file with java.
Create a File:
To create a file in Java, you 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.
In the following example, we use the FileWriter class together with its write() method to write some text to the file we created in the example above.
In the following example, we use the Scanner class to read the contents of the text file we created:
To delete a file in Java, use the delete() method:
0 Comments