~/ learn/ comp-308/ cards/ Scanner for tokenized input
1 of 6

Type the canonical read-every-line loop

Type the canonical read-every-line loop

Answer

try (Scanner sc = new Scanner(new File("examples1.txt"))) { while (sc.hasNextLine()) { String line = sc.nextLine().trim(); if (line.isEmpty()) continue; parseEvent(line); } }

try-with-resources closes the Scanner automatically. hasNextLine() guards the loop; trim() + isEmpty() skips blank lines before handing each line to the parser.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/f18ed4fa-9592-4f37-9968-d0069ddd3033/flashcard utf-8 LF