← Java Foundations

Week 7: File I/O

May 11 – May 15  ·  8 lessons  ·  Typed File Statistics lab  ·  APE prep

Objectives

  • Read a file with new Scanner(new File(path)) and declare throws FileNotFoundException on main
  • Loop until end of file with hasNext, hasNextLine, hasNextInt, hasNextDouble
  • Order the cascade hasNextInt before hasNextDouble and recognize the leftover-newline trap on sight
  • Write a file with new PrintStream(new File(path)), using the same print/println/printf API as System.out
  • Apply the count-allocate-fill pattern when the array size depends on the file's contents
  • Recognize BufferedReader, PrintWriter, FileWriter, BufferedWriter in real code without writing them yet
  • Open a file in append mode and create parent directories with getParentFile().mkdirs()
  • Tag each sentence of an APE File I/O spec with its four-step role (validate, operate, handle errors, update state) before writing code

Cadence

  • Mon: searching/sorting in a file context (lesson 7a)
  • Tue: File class, Scanner-on-File, throws (7b)
  • Wed: the cascade and PrintStream (7c, 7d)
  • Thu: 15-min array-tracing quiz, then APE warm-up
  • Fri: APE File I/O deep dive (7e, 7h)