Skip to content

Commit

Permalink
Create directory for save file if does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
koh-jx committed Aug 24, 2021
1 parent a7664de commit 7c25152
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 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/
/data/TaskList.txt
/text-ui-test/ACTUAL.txt
text-ui-test/EXPECTED-UNIX.TXT
src/main/java/META-INF
8 changes: 7 additions & 1 deletion src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class Storage {

private static final String FILE_LOCATION = "data\\TaskList.txt";
private static final String PATH_LOCATION = "data";

public static void saveList(ArrayList<Task> tasks) {
try {
Expand Down Expand Up @@ -44,7 +45,12 @@ public static TaskList loadList() {
return new TaskList(loaded);

} catch (FileNotFoundException e) {
System.out.println("Save file not found, using new file");
System.out.println("Save file not found, creating new file");
// Create directory if doesn't exist
File directory = new File(PATH_LOCATION);
if (! directory.exists()){
directory.mkdir();
}
return new TaskList();

} catch (ParseException | IllegalArgumentException e) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/duke/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Ui {
* Welcome text to display when duke.Duke starts up
*/
public static void intro() {
String welcomeText = "When the duke.Duke is sus";
String welcomeText = "When the Duke is sus";

String mascot ="\n" +
" `:ossys/` \n" +
Expand Down Expand Up @@ -41,7 +41,7 @@ public static void intro() {
);
System.out.println(
Ui.LINE +
"Hello! I'm duke.Duke!\n" +
"Hello! I'm Duke!\n" +
"What can I do for you?\n" +
Ui.LINE
);
Expand Down

0 comments on commit 7c25152

Please sign in to comment.