Course contentsShow
← Java
Lesson 1932 of 2,87039. File I/O: Basic Byte StreamsFree lesson

The Problem with Unbuffered I/O: System Call Overhead

Learn why reading/writing one byte at a time causes thousands of expensive system calls and slows performance.

The Problem with Unbuffered I/O: System Call Overhead

What you'll learn: Why reading or writing one byte at a time with raw streams creates a massive performance bottleneck.

The Hidden Cost of System Calls

When you use FileInputStream.read() or FileOutputStream.write(int) to process files byte-by-byte, each call triggers a system call—a request to the operating system to physically access the disk. System calls are expensive operations that involve context switching between your Java application and the OS kernel.

The Scale of the Problem

Imagine reading a 100 KB file one byte at a time:

  • 100,000 bytes = 100,000 system calls
  • Each system call takes microseconds, but they add up fast
  • Total overhead can be 10–100× slower than necessary

The Analogy

Think of it like grocery shopping:

Unbuffered I/O is like making a separate trip to the store for each individual item—milk on Monday, bread on Tuesday, eggs on Wednesday. You spend most of your time driving back and forth (system call overhead) rather than actually shopping.

Buffered I/O (which you'll learn next) is like using a shopping cart to buy everything in one trip—far more efficient.

Why Byte Arrays Help (But Aren't Enough)

Using read(byte[]) with a buffer reduces system calls dramatically—maybe 100 calls instead of 100,000. But you still manage the buffer manually. Java provides wrapper streams that handle this automatically and more efficiently.

Key Takeaway: Unbuffered byte-by-byte I/O generates thousands of expensive system calls, creating severe performance overhead. Always prefer reading/writing in larger chunks or use buffered streams for real-world applications.