aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer Science HLTopic 6.5
Unit 6 · Programming · Topic 6.5

IB Computer Science HL — File processing

File processing

Higher Level students should use this topic hub as a map: start with the shared sub-topics, then follow the HL-only extensions and exam-skill links where this topic asks for deeper analysis.

Exam technique guidePractice questions

Key concepts in File processing

Key Idea: A file keeps data after the program ends. Everything about file handling follows from two facts: writes are buffered, and the file may not be what the program expects.

Paper 1

  • Short definitions and a trace.
  • State, identify, outline — precise terms.

Paper 2

  • Write or correct Python for a scenario — your paper is the Python version, option B.
  • Construct, determine, suggest.

Both

  • Trace tables and justified choices earn method marks even when the final answer slips.

📂 The operations

Open, read or write, close

  • Closing flushes the buffer — without it the most recent writes can be lost entirely
  • Closing also releases resources; a loop that never closes exhausts them
  • Opening for WRITING discards the existing contents the moment it opens
  • Opening for APPENDING preserves them — which is why a log must be opened that way
  • The buffer exists because writing to disc one byte at a time would be far too slow
For fixed-length records: byte position = record number × record length record number = byte position ÷ record length Variable-length records make direct access impossible without an index.

🎯 Access methods

SequentialDirect
ReadsFrom the start, in orderJumps to a calculated position
NeedsNothing specialFixed-length records or an index
Cost of record nPass everything before itConstant, whatever n is
SuitsProcessing every recordLooking one record up
Text fileBinary file
ReadableIn any editorOnly with the exact layout
SizeLargerCompact
LoadingNeeds conversionNo conversion
Diagnosing a faultBy eyeRequires a tool

🔐 Writing safely

Important: A failure part-way leaves neither version complete. Write to a temporary file, then rename it over the original — a rename either happens or it does not, so there is no half-written state.

Reading defensively

  • Never assume a file is correctly formatted — it may be hand-edited, truncated, or from an older version
  • Validate each record as it is read, so one bad line is reported and skipped
  • A comma inside a value breaks a comma-separated file: quote it or choose another separator
  • A missing file, a locked file and a full disc are all normal — handle them, do not assume them away

📝 Exam-style questions

IB-style questionCalculate[4 marks]

A file stores 12 000 records of 96 bytes each, with a 512-byte header. Calculate the file size in kilobytes (1 KB = 1024 bytes), and the byte position at which record 500 begins (records numbered from 0, immediately after the header).

🔒 Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic →
IB-style questionExplain[3 marks]

A program appends a line to a log file inside a loop and the computer loses power. Some lines written seconds earlier are missing. Explain why, and state what would prevent it.

🔒 Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic →

✅ Quick check

Cover the answers.

What does closing a file do beyond ending access? Flushes the buffer to disc and releases the resources the open file holds.

Which open mode destroys the existing contents? Opening for writing — and it does so the moment it opens, before anything is written.

Why does direct access need fixed-length records? The position is calculated as record number × record length — impossible if lengths vary.

How do you replace a file safely? Write a temporary file, then rename it over the original — a rename cannot half-happen.

Why is a text file often preferred despite being larger? It is readable in any editor, so a fault can be diagnosed by eye and the data survives the program that wrote it.


Exam tips

  • File-size questions are arithmetic with units — read whether bytes, KB or MB is wanted.
  • Include the header in both the size and the position calculation.
  • Records numbered from 0: record n starts at header + n × length.
  • Name the BUFFER when explaining lost writes — that is the marked point.
  • Write mode destroys; append mode preserves. Say which a log needs.
  • Never overwrite in place — temporary file, then rename.

What you'll learn in Topic 6.5

  • 6.5.1 File processing
Suggested study order: Read the notes for each sub-topic below → test yourself with flashcards → attempt practice questions → review exam technique.

Study resources — 6.5 File processing

6.5.1

File processing

Notes

Ready to study File processing?

Get expert practice questions with instant AI feedback, and a study planner tailored to your IB Computer Science HL exam date.

Start studying free

Topic 6.5 File processing forms a core part of Unit 6: Programming in IB Computer Science HL. Mastering these concepts will strengthen your understanding of connected topics across the syllabus and prepare you for exam questions that require analysis, evaluation, and real-world application.

Previous topic
6.4 Programming algorithms
Next topic
7.1 OOP: a single class
All Computer Science HL topics
Exam technique

Ready to practice?

Get AI-graded practice questions, mock exams, flashcards, and a personalised study plan — all aligned to your IB syllabus.

Start Studying Free

No credit card required · No time limit