From 8eb6d271e4d5bef4575083c0dfe0a79f950bcad8 Mon Sep 17 00:00:00 2001 From: SowinskiBraeden Date: Mon, 17 Nov 2025 13:47:42 -0800 Subject: [PATCH] use BufferedReader instead of Scanner --- src/code/ca/bcit/comp2522/lab09/WordList.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/code/ca/bcit/comp2522/lab09/WordList.java b/src/code/ca/bcit/comp2522/lab09/WordList.java index 13b9849..0030900 100644 --- a/src/code/ca/bcit/comp2522/lab09/WordList.java +++ b/src/code/ca/bcit/comp2522/lab09/WordList.java @@ -1,7 +1,10 @@ package ca.bcit.comp2522.lab09; +import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Random; @@ -26,21 +29,21 @@ public class WordList * @throws FileNotFoundException if the file cannot be opened. */ public WordList(final String filePath) - throws FileNotFoundException + throws IOException { this.wordList = new ArrayList<>(); - final Scanner fileScanner; - final File file = new File(filePath); + final BufferedReader reader; - fileScanner = new Scanner(file); + reader = new BufferedReader(new FileReader(filePath)); - while (fileScanner.hasNextLine()) + String line; + while((line = reader.readLine()) != null) { - this.wordList.add(fileScanner.nextLine()); + this.wordList.add(line); } - fileScanner.close(); + reader.close(); } /**