Knowledge Organiser: File Handling
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 →