diff --git a/.gitignore b/.gitignore index ccb4f7cc58..f1b66e96b1 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ bin/ /text-ui-test/ACTUAL.TXT text-ui-test/EXPECTED-UNIX.TXT data/tasks.txt +data/tasks diff --git a/src/main/java/cook/Cook.java b/src/main/java/cook/Cook.java index 82bbf758e2..b3a79d1111 100644 --- a/src/main/java/cook/Cook.java +++ b/src/main/java/cook/Cook.java @@ -72,6 +72,6 @@ public static void exit() { * Creates a new Cook chatbot and runs it. */ public static void main(String[] args) { - new Cook(new File("data", "tasks.txt")).run(); + new Cook(new File("data", "tasks")).run(); } } diff --git a/src/main/java/cook/Storage.java b/src/main/java/cook/Storage.java index 91f56f0518..04ec47f44b 100644 --- a/src/main/java/cook/Storage.java +++ b/src/main/java/cook/Storage.java @@ -43,6 +43,8 @@ public TaskList readFile() throws IOException, ClassNotFoundException { * @throws IOException If file cannot be written to. */ public void writeFile(TaskList tasks) throws IOException { + this.file.getParentFile().mkdirs(); + this.file.createNewFile(); // Solution below adapted from https://stackoverflow.com/questions/10404698/saving-arrays-to-the-hard-disk ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(this.file)); out.writeObject(tasks); diff --git a/src/main/java/javafx/Main.java b/src/main/java/javafx/Main.java index db4496f5dd..39f04ced4f 100644 --- a/src/main/java/javafx/Main.java +++ b/src/main/java/javafx/Main.java @@ -15,7 +15,7 @@ */ public class Main extends Application { - private Cook cook = new Cook(new File("data", "tasks.txt")); + private Cook cook = new Cook(new File("data", "tasks")); @Override public void start(Stage stage) {