Skip to content

Commit

Permalink
Resolve error when no initial file
Browse files Browse the repository at this point in the history
  • Loading branch information
blank-bank committed Feb 19, 2021
1 parent 0c1a7a2 commit 24f5b2f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/main/java/duke/main/Duke.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package duke.main;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;

import duke.exceptions.*;
import duke.items.*;

import static duke.main.Utils.createFile;
import static duke.main.Utils.loadFile;

public class Duke {
Expand All @@ -16,8 +18,8 @@ public static void main(String[] args) {
Utils.printLine();
try {
loadFile();
} catch (IOException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
createFile();
}
Scanner in = new Scanner(System.in);
while (true) {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/duke/main/Utils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package duke.main;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import duke.exceptions.*;
Expand Down Expand Up @@ -78,7 +79,7 @@ public static void writeToFile() throws IOException {
fw.close();
}

public static void loadFile() throws IOException{
public static void loadFile() throws FileNotFoundException {
File f = new File("list.txt"); // create a File for the given file path
Scanner s = new Scanner(f); // create a Scanner using the File as the source
while (s.hasNext()) {
Expand Down

0 comments on commit 24f5b2f

Please sign in to comment.