Skip to content

Commit 24f5b2f

Browse files
committed
Resolve error when no initial file
1 parent 0c1a7a2 commit 24f5b2f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/main/java/duke/main/Duke.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package duke.main;
22

3+
import java.io.FileNotFoundException;
34
import java.io.IOException;
45
import java.util.Scanner;
56

67
import duke.exceptions.*;
78
import duke.items.*;
89

10+
import static duke.main.Utils.createFile;
911
import static duke.main.Utils.loadFile;
1012

1113
public class Duke {
@@ -16,8 +18,8 @@ public static void main(String[] args) {
1618
Utils.printLine();
1719
try {
1820
loadFile();
19-
} catch (IOException e) {
20-
e.printStackTrace();
21+
} catch (FileNotFoundException e) {
22+
createFile();
2123
}
2224
Scanner in = new Scanner(System.in);
2325
while (true) {

src/main/java/duke/main/Utils.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package duke.main;
22

33
import java.io.File;
4+
import java.io.FileNotFoundException;
45
import java.util.ArrayList;
56
import java.util.Arrays;
67
import duke.exceptions.*;
@@ -78,7 +79,7 @@ public static void writeToFile() throws IOException {
7879
fw.close();
7980
}
8081

81-
public static void loadFile() throws IOException{
82+
public static void loadFile() throws FileNotFoundException {
8283
File f = new File("list.txt"); // create a File for the given file path
8384
Scanner s = new Scanner(f); // create a Scanner using the File as the source
8485
while (s.hasNext()) {

0 commit comments

Comments
 (0)