CHAPTER 22
Beginner
File Handling in Java
Updated: May 17, 2026
5 min read
# CHAPTER 22
File Handling in Java
1. Introduction
Real applications work with files — reading configuration files, saving user data, generating reports, and processing logs. Java provides multiple APIs for file operations, from the classicjava.io package to the modern java.nio.file package.
2. Creating and Checking Files
java
3. Writing to Files
java
4. Reading Files
Using BufferedReader:
java
Using java.nio.file (Modern approach):
java
5. Appending to Files
java
6. Deleting Files
java
7. Serialization Basics
Converting an object to bytes for storage:
java
8. Mini Project: Notes Application
java
9. MCQ Quiz with Answers
Question 1
Which class writes text to files?
Question 2
BufferedReader reads files:
Question 3
new FileWriter("f.txt", true) means:
Question 4
try-with-resources automatically:
Question 5
Serializable is a:
Question 6
Files.readAllLines() is from:
Question 7
FileNotFoundException is a:
Question 8
To check if a file exists:
Question 9
ObjectOutputStream is used for:
Question 10
file.delete() returns:
10. Summary
Java provides FileWriter/BufferedWriter for writing and FileReader/BufferedReader for reading files. The modernjava.nio.file API offers cleaner alternatives. Always use try-with-resources to prevent resource leaks. Serialization converts objects to bytes for persistent storage.