B2.5 File processing - IB Diploma Class 11 Computer Science Notes, Diagrams and Solved Questions
Making data last beyond one run of a program, in Python and Java: opening and closing text files, read, write and append modes, reading line by line, writing results, processing comma-separated records, and handling file exceptions safely.
In this chapter
Why files are needed and the open, read/write, close pattern
Read, write and append modes in Python and Java
Reading a file line by line with for, readLine and Scanner
Writing lines with write and PrintWriter
Appending entries to a growing log
Processing comma-separated records with split and writing a results file
Handling FileNotFoundError and FileNotFoundException
Iteration 3: updating a record, skipping bad lines and searching a file