Knowledge Organiser: File Handling

Part of File Handling ยท Section 7 of 7

Topic SummaryUnit: 3.2 ProgrammingGCSE

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

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.

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 โ†’

PrepWise is a trading name of A3M Quality Solutions Limited, registered in England and Wales, company number 14959172. Registered office: 202 Stroud Road, Gloucester, GL1 5LA. ICO registration ZC267069.