mirror of
https://github.com/smyalygames/kahoot-challenge-2025.git
synced 2025-05-18 17:04:14 +02:00
refactor: remove the throw argument for open file, and add try catch
This commit is contained in:
parent
9b031e3da6
commit
0dbd6eb471
@ -10,15 +10,20 @@ public class ReadFile {
|
|||||||
* @param filename the name of the file with, only allowing a .txt extension
|
* @param filename the name of the file with, only allowing a .txt extension
|
||||||
* @return The contents of the file
|
* @return The contents of the file
|
||||||
*/
|
*/
|
||||||
public List<String> open(String filename) throws IllegalArgumentException, FileNotFoundException {
|
public List<String> open(String filename) {
|
||||||
// Check that the filetype is correct, otherwise, throw IllegalArgumentException
|
// Check that the filetype is correct, otherwise, throw IllegalArgumentException
|
||||||
if (!filename.endsWith(".txt")) {
|
if (!filename.endsWith(".txt")) {
|
||||||
throw new IllegalArgumentException("The filename is not a .txt format");
|
throw new IllegalArgumentException("The filename is not a .txt format");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open the file that was defined
|
|
||||||
File file = new File(filename);
|
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 for all the separate lines on the database
|
||||||
List<String> data = new ArrayList<>();
|
List<String> data = new ArrayList<>();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user