Knowledge Organiser: File Handling

Part of File Handling · Section 7 of 7

Topic SummaryUnit: 3.2 ProgrammingGCSE

This topic summary covers Knowledge Organiser: File Handling 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 7 of 7 in this topic. Use this topic summary to connect the idea to the wider topic before moving on to questions and flashcards.

Knowledge Organiser: File Handling

Key Terms
  • File: A named collection of data stored permanently on secondary storage
  • open(): Opens a file for reading
  • openWrite(): Opens a file for writing — overwrites existing content
  • readLine(): Reads the next line from an open file
  • writeLine(): Writes a line of text to a file
  • endOfFile(): Returns true when there are no more lines to read
  • close(): Closes a file after use — must always be called
Must-Know Facts
  • Variables are temporary; files provide permanent storage that survives program shutdown
  • Files must always be closed after use — leaving them open can cause data loss
  • openWrite() overwrites the file; use append mode if you want to add to existing content
  • Use endOfFile() in a WHILE loop to read all lines without going past the end
  • The three steps are: Open, Read/Write, Close (ORC)
Key Concepts
  • Open for reading: myFile = open("data.txt")
  • Read all lines: while NOT myFile.endOfFile() ... line = myFile.readLine() ... endwhile
  • Write to file: myFile = openWrite("out.txt") ... myFile.writeLine("text")
  • Always close: myFile.close()
Common Mistakes
  • Forgetting to close the file: Not calling close() after reading/writing can cause data loss or file corruption — always close as the final step
  • Confusing open() and openWrite(): open() is for reading; openWrite() is for writing and will overwrite all existing content — using the wrong one destroys data
  • Not using endOfFile() in a loop: Reading past the end of a file causes a runtime error — always use a WHILE NOT endOfFile() loop to read all lines safely
  • Thinking variables and files work the same way: Variables are temporary (lost when the program ends); files are permanent storage on secondary storage — a key distinction examiners test
  • Writing pseudocode file handling without open/close: Exam mark schemes require open, read/write, and close — missing either the open or close step loses marks

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

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

15 questions on File Handling — practise free

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

Start revising free →