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)