Skip to content

Commit

Permalink
Fix save/load file
Browse files Browse the repository at this point in the history
  • Loading branch information
lm-44 committed Sep 17, 2024
1 parent 1ba8c7c commit bd85fbe
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ bin/
/text-ui-test/ACTUAL.TXT
text-ui-test/EXPECTED-UNIX.TXT
data/tasks.txt
data/tasks
2 changes: 1 addition & 1 deletion src/main/java/cook/Cook.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 2 additions & 0 deletions src/main/java/cook/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/javafx/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bd85fbe

Please sign in to comment.