ProgrammingTopic Summary

Knowledge Organiser: File Handling

Part of File Handling · GCSE GCSE Computer Science revision

This topic summary covers Knowledge Organiser: File Handling within File Handling for GCSE Computer Science. Revise File Handling in Programming for GCSE Computer Science with 15 exam-style questions and 10 flashcards. This topic appears regularly enough that it should still be part of a steady revision cycle. 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.

Topic position

Section 7 of 7

Practice

15 questions

Recall

10 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

Revise this topic interactively on PrepWise — self-test mode, tap-to-reveal definitions, and Common Mistakes from examiners.

Try the interactive Knowledge Organiser — free →

Keep building this topic

Read this section alongside the surrounding pages in File Handling. That gives you the full topic sequence instead of a single isolated revision point.

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 10 spaced repetition flashcards. Free until your GCSEs.

Try PrepWise Free