Skip to content
Marlbridge

AP® Computer Science A · Unit 4 · Topic 4.6

Using Text Files: Checklist (Computer Science A 4.6)

A self-check for reading text files in Java: connecting a Scanner to a File, looping with hasNext, choosing the right Scanner method, using split, and handling exceptions.

Tick each line when you can do it without looking at the guide. Each line names where it is taught and tested. Revisit the study guide for anything you cannot yet do.

Understanding

  • ☐ I can explain why a file is needed to keep data after the program ends (study guide: Why programs need files).
  • ☐ I can name the imports and the header clause needed to read a file (study guide: The standard pattern; practice: Question 1).
  • ☐ I can describe the Scanner cursor and say why it never moves backwards (study guide: The Scanner methods you need; Figure 1).
  • ☐ I can say what hasNext() does and that it does not move the cursor (practice: Question 7).

Skills

  • ☐ I can write the five-step pattern: File, Scanner, hasNext loop, read, close (study guide: Worked example 1; practice: Question 9).
  • ☐ I can trace a Scanner loop token by token and give the final result (study guide: Worked example 1; practice: Question 2).
  • ☐ I can choose between next, nextInt, nextDouble, nextBoolean and nextLine for a given file layout (practice: Questions 5 and 8).
  • ☐ I can read records line by line, split them and convert a field to a number (study guide: Worked example 2; practice: Question 10).

Reasoning

  • ☐ I can predict which exception is thrown for a wrong-kind token or for reading past the end (practice: Questions 3 and 6).
  • ☐ I can predict the length of a split result, including dropped trailing empty strings (practice: Question 4).
  • ☐ I can explain why > and >= give different answers when records tie (study guide: Worked example 2).
  • ☐ I can say what happens when the file is empty (study guide: Common misconceptions; practice: Question 10).

Next: Topic 4.7 wrapper classes.

AP® and Advanced Placement® are trademarks registered by the College Board, which is not affiliated with, and does not endorse, this website. Marlbridge is an independent tuition provider. It is not an authorized AP course provider, an AP school or an exam centre, and these resources are not official College Board materials. Reading them or doing simulations does not meet the laboratory requirement of an AP science course.