Practice question · Select all that apply
Select every statement that is true of the stream model and file handling.
Hints
- One option flatly contradicts the whole reason streams exist.
- Think about how a program reads a file that is bigger than its memory.
Show the answer
- B. A stream reads a file a piece at a time
- C. Opening a file requires choosing a read or write mode
- D. Closing a file flushes writes that were still buffered
- E. Streaming lets a program handle a file larger than available memory
Why
Streaming reads incrementally, which is exactly what lets a program exceed memory; closing flushes buffered writes; opening picks a mode. The false option is that a file must be fully loaded first, that is what the stream model is designed to avoid.
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
- The open-process-close discipline requires closing a file even when processing fails partway through. Why…
- Match each I/O idea to what it means.
- A program writes to a file, crashes, and the file turns out empty, although the writes clearly executed.…
- Sort each action by whether it is input or output.
- Order the steps a program takes to read a number from the user and add ten to it.