Deep Dive: Reading All Lines

Part of File Handling · Section 4 of 7

Study NotesUnit: 3.2 ProgrammingGCSE

This study notes covers Deep Dive: Reading All Lines within File Handling for GCSE Computer Science. Revise File Handling in 3.2 Programming for GCSE Computer Science with 15 exam-style questions and 10 flashcards. This is a high-frequency topic, so it is worth revising until the explanation feels precise and repeatable. It is section 4 of 7 in this topic. Use this study notes to connect the idea to the wider topic before moving on to questions and flashcards.

Deep Dive: Reading All Lines

// Read all lines from a file
myFile = open("data.txt")
while NOT myFile.endOfFile()
    line = myFile.readLine()
    print(line)
endwhile
myFile.close()

Always close files! Leaving files open can cause data loss or corruption.

Practice questions for File Handling

Which OCR pseudocode command is used to open a file called 'scores.txt' for reading?

  • A. read("scores.txt")
  • B. myFile = open("scores.txt")
  • C. file.open("scores.txt", "r")
  • D. load("scores.txt")
1 markfoundation

Describe how OCR pseudocode reads all lines from a text file, using a WHILE loop. Include the role of endOfFile() in your answer.

3 marksstandard

Quick recall flashcards

Why must you close files?
To save data and prevent corruption
How do you read a line?
line = myFile.readLine()

15 questions on File Handling — practise free

Instant marking, adaptive difficulty and spaced-repetition flashcards — all aligned to your exam board.

Start revising free →