use BufferedReader instead of Scanner

This commit is contained in:
SowinskiBraeden committed 2025-11-17 13:47:42 -08:00
1 parent 2b041e6918
commit 8eb6d271e4
1 file changed
+10 -7
+10 -7
View File
@@ -1,7 +1,10 @@
package ca.bcit.comp2522.lab09; package ca.bcit.comp2522.lab09;
import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
@@ -26,21 +29,21 @@ public class WordList
* @throws FileNotFoundException if the file cannot be opened. * @throws FileNotFoundException if the file cannot be opened.
*/ */
public WordList(final String filePath) public WordList(final String filePath)
throws FileNotFoundException throws IOException
{ {
this.wordList = new ArrayList<>(); this.wordList = new ArrayList<>();
final Scanner fileScanner; final BufferedReader reader;
final File file = new File(filePath);
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();
} }
/** /**