File handling allows a program to save data to a file and read data from a file. This is important for storing information permanently.
Java provides built-in classes like File, Scanner, and FileWriter to work with files.
You can create a new file using the createNewFile() method. This method throws an exception if something goes wrong.
Use FileWriter to write text to a file. This will overwrite the file unless you enable append mode.
Use the Scanner class to read file content line by line.
To add content without deleting existing data, enable append mode by passing true to FileWriter.
You can delete a file using the delete() method from the File class.
File operations can fail due to missing files or permission issues. Use try-catch to handle these safely.
Create a program that writes student names to a file, reads them back, and prints them.