GCSE Computer Science Revision — File Handling
Revise File Handling for GCSE Computer Science with a topic explanation, worked example and common mistakes. Check the board notes for specification differences.
At a glance
- What StudyVector is
- An exam-practice platform with board-aligned questions, explanations, and adaptive next steps.
- This topic
- File Handling in GCSE Computer Science: explanation, examples, and practice links on this page.
- Who it’s for
- Students revising GCSE Computer Science for UK exams.
- Exam boards
- Check your course page and the topic board notes for supported specifications.
- Free plan
- Sign up free to use tutor paths and feedback on your answers. Free access is Free daily revision · No card required. Pricing
- What makes it different
- Syllabus-shaped practice and progress tracking—not generic AI answers.
This page includes a topic explanation and a worked example. Check your course for current practice coverage.
Next in this topic area
Next step: SQL & Databases
Continue in the same course — structured practice and explanations on StudyVector.
Go to SQL & DatabasesTopic explanation
What is File Handling?
File handling allows a program to read data from and write data to external files. This is essential for making data persistent, meaning it is saved even after the program has stopped running. Programs can open files in different modes, such as read mode to access existing data, write mode to create a new file or overwrite an old one, and append mode to add new data to the end of a file.
Board notes: All GCSE boards (AQA, Edexcel, OCR) cover basic file handling. You will be expected to know how to open, read from, write to, and append to simple text files (.txt) or comma-separated value files (.csv).
Step-by-step explanationWorked examples
Worked example
To save a user's score to a file named `score.txt` in Python: `with open('score.txt', 'w') as f: f.write('150')`. The `with` statement is good practice as it automatically closes the file. To read the score back: `with open('score.txt', 'r') as f: score = f.read()`. The variable `score` would then contain the string '150'.
Practise this topic
Start with low-focus cards for File Handling, then move into full exam-style practice when you want the heavier session.
Common mistakes
- 1Forgetting to close a file after opening it. This can lock the file and, in some cases, lead to data loss as the changes might not be saved until the file is properly closed.
- 2Trying to read from a file that has been opened in write mode, or write to a file opened in read mode. This will cause a runtime error.
- 3Confusing write mode and append mode. Write mode (`w`) will erase the entire contents of an existing file, while append mode (`a`) will simply add to the end of it.
File Handling exam questions
Check the available question sets for File Handling. Use your course and exam board to confirm which practice is relevant.
File Handling exam questionsGet help with File Handling
Get a personalised explanation for File Handling from the StudyVector tutor. Ask follow-up questions and work through problems with step-by-step support.
Open tutorSave your progress in File Handling
Start a free account for low-focus question cards, feedback and Play routes across available topics. Free daily limits apply; no card required.
Continue your revision
A public question for File Handling is still being reviewed. Your course page shows the topics currently available for practice.
Continue with File Handling
Create a free account to keep your course choice and save your practice progress.
Start free low-focus cardsAlready have an account? Log in
Frequently asked questions
What is the difference between reading a file line by line versus all at once?
Reading a file all at once with `.read()` is simple but can use a lot of memory for large files. Reading line by line, for example using a loop, is more memory-efficient as it only processes one line at a time.
How do you handle errors when a file doesn't exist?
You should use a `try...except` block. You `try` to open the file, and if a `FileNotFoundError` occurs, the `except` block can handle it gracefully, for example by printing an error message instead of crashing the program.