File handling – OCR GCSE Computer Science lesson (J277)
Pupils learn to write a program that opens a text file, writes data to it, reads it back and closes it, choosing the right mode for each job.
Lesson 3 of 13 in unit 11.2 Systems Software, Languages and Data Handling, taught in Year 11, Autumn 2. It answers one big question: How can a program remember data after it closes?
By the end, pupils can write a program that opens a text file, writes data to it, reads it back and closes it, choosing the right mode for each job.
- The Build (the main task)
- Write a program that asks for a pet's name and appointment time, adds them to appointments.txt, then reads the file and prints every appointment.
- Support version
- Parsons problem: the program's lines jumbled, with one distractor line that opens the file in write mode.
- Challenge
- Count the appointments in the file, and add up the minutes of a file of appointment lengths (converting each line to an integer).
- Real-world link
- The booking app must keep today's appointments even if the PC is switched off.
- Key words
- File handling, Text file and Permanent, each with a definition, an icon and a common mix-up on the key vocabulary slide.
- Misconceptions it tackles
- “Opening a file in write mode adds the new data to the end”; “Numbers read from a text file are integers that can be added straight away”.
- OCR J277 specification
- 2.2.3 (additional programming techniques: file handling (open, read, write, close), records to store data, and SQL (SELECT, FROM, WHERE) to search for data).
Every lesson follows the same Code & Commerce structure: a Bell Task recall starter, key vocabulary with definitions and icons, short teaching chunks with a check before pupils move on, The Build (one main task), challenge questions that get harder, and an exit question. Answers reveal one at a time on the slides, and everything is editable PowerPoint and Word.
Pupils need computers for the main task.
Also sold in the Systems Software, Languages and Data Handling unit bundle, which includes the medium term plan, and in the full-year and complete-course bundles.
What's included
- Slide deck (PowerPoint)
- Lesson plan (Word)
- Worksheet (Word)
- Support worksheet with scaffolds (Word)
- Single-teacher licence: use and adapt it with your own classes
More for GCSE Computer Science (OCR)
See allPupils learn to explain how the operating system provides a user interface, allocates memory to programs and lets several programs run at once.
Free sample lessonPupils learn to explain how the operating system manages peripherals with device drivers, controls user accounts and access, and organises files.
Pupils learn to explain the purpose of defragmentation, data compression and encryption software and recommend which a computer needs.
Written for the specifications named. Not endorsed by or affiliated with any exam board.