Course contentsShow
← Computer Science
Lesson 1386 of 2,87232. File SystemsFree lesson

File Abstraction and Basic Operations

Learn what a file is, why the OS provides file abstractions, and the fundamental operations: open, read, write, close.

File Abstraction and Basic Operations

You'll learn what files are, why operating systems provide this abstraction, and the four fundamental operations that make files useful.

What is a File?

A file is the OS's abstraction for persistent storage. Just as virtual memory gives each process the illusion of private address space, a file gives programs a simple, uniform interface to store and retrieve data—whether it lives on a hard disk, SSD, network drive, or USB stick.

Without files, your program would need to understand disk sectors, track locations, and hardware specifics. The file abstraction hides all that complexity behind a simple name (like report.txt) and a set of operations.

Why Files Matter

Files provide:

  • Persistence: Data survives after your program exits or the machine reboots
  • Naming: Human-readable identifiers instead of raw disk addresses
  • Protection: The OS can control who reads or writes each file
  • Abstraction: Same operations work across different storage devices

Think of a file like a labeled container in a warehouse. You don't need to know which shelf or aisle—just ask for it by name, and the warehouse (OS) handles retrieval.

The Four Core Operations

  1. open: Tell the OS you want to access a file; get back a file descriptor (a handle for subsequent operations)
  2. read: Copy data from the file into your program's memory
  3. write: Copy data from memory into the file
  4. close: Tell the OS you're done; release resources

These operations form the contract between application and OS, letting programs work with persistent data without worrying about hardware details.

Key Takeaway: Files are the OS abstraction for persistent storage, hiding hardware complexity behind simple operations—open, read, write, and close—that work uniformly across all storage devices.