diff --git a/src/ReadFile.java b/src/ReadFile.java index d947330..eb86761 100644 --- a/src/ReadFile.java +++ b/src/ReadFile.java @@ -10,25 +10,30 @@ public class ReadFile { * @param filename the name of the file with, only allowing a .txt extension * @return The contents of the file */ - public List open(String filename) throws IllegalArgumentException, FileNotFoundException { + public List open(String filename) { // Check that the filetype is correct, otherwise, throw IllegalArgumentException if (!filename.endsWith(".txt")) { throw new IllegalArgumentException("The filename is not a .txt format"); } - - // Open the file that was defined + File file = new File(filename); - Scanner reader = new Scanner(file); - + Scanner reader; + try { + // Open the file that was defined + reader = new Scanner(file); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + // List for all the separate lines on the database List data = new ArrayList<>(); - + // Go through all the lines in the file and append them to the list `data` while (reader.hasNextLine()) { String currentData = reader.nextLine(); data.add(currentData); } - + return data; } }