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.