CS102 · Files · Annotated SlidesFiles
Original
Overview

Files

Reading files with Scanner, writing with FileWriter/PrintWriter, and splitting lines with String.split.

How to read this page

Every original slide is shown unchanged. Yellow marks on a slide point to a numbered note: hover or tap a mark to jump to its note, and hover a note to see its marks. Questions tagged Past exam appeared on a real paper; Prediction questions are likely angles, not confirmed. Pick an answer to each question: a wrong pick tells you why it is wrong, so you can try again.

All 6 slides
  1. 1 Files Revision
  2. 2 Slide 2
  3. 3 FileWriter Class
  4. 4 Code Examples
  5. 5 Split Method
  6. 6 Split Coding Example
Slide 1 / 6

Files Revision

Slide 1: Files Revision

Notes

  1. Remember Integer.parseInt(string) to turn text fields into numbers.

Slide 2 / 6

Slide 2

Slide 2: Slide 2
Slide 3 / 6

FileWriter Class

Slide 3: FileWriter Class

Notes

  1. FileWriter writes characters; new FileWriter(name, true) APPENDS instead of overwriting.

Exam angle

PredictionQ1

new FileWriter("data.txt", true) will:

Slide 4 / 6

Code Examples

Slide 4: Code Examples
Slide 5 / 6

Split Method

Slide 5: Split Method

Exam angle

PredictionQ1

"Ali:20:A".split(":") returns an array of length:

Slide 6 / 6

Split Coding Example

Slide 6: Split Coding Example

Notes

  1. Read a line, split it, parse the numeric fields, display.