Computer Science I / Input, Output, and File Thinking
Practice question · Multiple choice

A program writes to a file, crashes, and the file turns out empty, although the writes clearly executed. Where did the data go?

Hints
  1. Ask where the bytes sit between the write call returning and the disk spinning.
  2. Why does closing a file matter if the writes already 'succeeded'?
Show the answer

C. It was still in a buffer, flushed only on close or when the buffer fills

Why

Buffering makes writes fast by batching them, so a successful write call means the data reached a buffer rather than the disk. Closing flushes it, which is why with blocks, RAII and try-with-resources exist, and why a crash is precisely the case that skips a manual close.

Read the lesson: Input, Output, and File Thinking →

Practise Input, Output, and File Thinking

The app has 5 more questions on this lesson, and keeps your place in the course. Computer Science I is free to start.

More questions on Input, Output, and File Thinking