What is File Handling?
File Handling in Java is the process of creating, reading, writing, updating, and deleting files using Java programs.
👉 It helps programs to store data permanently instead of only in memory.
📁 What is a File?
A file is a collection of data stored in a storage device (like hard disk).
👉 Examples:
notes.txtdata.pdfimage.jpg
📂 What is a Directory (Folder)?
A directory (folder) is a container used to store files and other folders.
👉 Example:
Documents/
├── notes.txt
├── resume.pdf
└── Images/
⚙️ What is the File Class?
The File class in Java is used to:
- Create files
- Check file properties
- List files and folders
- Delete files
👉 It belongs to:
java.io package
🔑 Important Methods (Definition)
-
createNewFile()→ Creates a new file -
listFiles()→ Lists all files in a directory -
isFile()→ Checks if it is a file -
isDirectory()→ Checks if it is a folder -
getName()→ Returns file/folder name -
delete()→ Deletes a file
🔤 String Methods Used in File Handling
👉 File handling often uses String methods:
-
toLowerCase()→ ignore case -
endsWith()→ check file type -
substring()→ extract extension -
lastIndexOf()→ find extension position
💾 Why File Handling is Important?
- Store data permanently
- Read/write application data
- Work with system files
- Used in real-world apps (logs, configs, reports)
Short Conclusion
File handling is a core concept in Java that allows developers to interact with system files and build practical applications.
Top comments (0)