Skip to content

Module 5: File I/O & Streams (The Filing Cabinet)

📚 Module 5: File I/O & Streams

Course ID: DOTNET-103
Subject: The Filing Cabinet

As a Data Engineer, your primary job is moving data. In .NET, we don’t just “Open files.” We use Streams to flow data efficiently without filling up our RAM.


🏗️ Step 1: The File Stream (The “Straw”)

Imagine you have a 10GB file. You only have 8GB of RAM.

  • Bad way: You try to “Gulp” the whole file into memory. (The app crashes).
  • Senior way: You use a Stream. It’s like a tiny Straw. You sip the data byte by byte.

🏗️ Step 2: StreamReader vs. File.ReadAllText

  • File.ReadAllText: Great for tiny files (Config files, Readmes).
  • StreamReader: Essential for large logs or datasets.

🧩 The Analogy: The Conveyor Belt

  • Reading a whole file is like carrying a giant box.
  • Using a Stream is like a Conveyor Belt. You stand in one place and process each item as it passes by.

🏗️ Step 3: Why do we use ‘using’?

In .NET, files are “External Resources.” If you open a file and don’t close it, nobody else can touch it until your app dies.

  • The using keyword is like a Self-Closing Door. As soon as you finish reading, it slams shut and releases the file.

🥅 Module 5 Review

  1. Stream: A “Straw” for data flow.
  2. Using: Automatically closing doors.
  3. Buffer: A tiny waiting room for data.