Lesson Plan

Lesson Plan
Grade: Date: 17/01/2026
Subject: Computer Science
Lesson Topic: Write code to perform file-processing operations
Learning Objective/s:
  • Describe the difference between character and byte streams in Java.
  • Write Java programs that read from and write to text files using BufferedReader and PrintWriter.
  • Apply try‑with‑resources to ensure streams are closed automatically.
  • Implement exception handling for I/O operations, including custom exceptions.
  • Process binary files with DataInputStream and DataOutputStream.
Materials Needed:
  • Projector and screen
  • Java IDE or code editor
  • Sample text and binary files
  • Printed handout of stream classes and exception syntax
  • Whiteboard and markers
Introduction:
Begin with a quick discussion on why programs need to store data beyond a single run, linking to students’ recent work with arrays. Recall the concept of streams introduced last week and set the success criteria: students will be able to read, write, and safely handle errors in both text and binary files.
Lesson Structure:
  1. Do‑now (5'): Students answer a short quiz on stream terminology on the board.
  2. Mini‑lecture (10'): Review character vs byte streams and the try‑with‑resources syntax, using the projector.
  3. Guided coding (15'): Walk through reading a text file with BufferedReader, then writing with PrintWriter, highlighting exception handling.
  4. Pair programming (15'): Learners modify the example to process a CSV file, adding a custom InvalidRecordException and logging skipped lines.
  5. Binary file demo (10'): Demonstrate DataOutputStream/DataInputStream to write and read primitive values, followed by a quick check for understanding.
  6. Exit ticket (5'): Students write one line summarising how they will ensure resources are closed in future code.
Conclusion:
Summarise the key steps of file processing and the importance of robust exception handling. Collect exit tickets and remind students to complete the homework worksheet that asks them to implement a file‑copy utility with proper error handling.