Skip to content

Commit 009b413

Browse files
committed
made changes to Storage.java
1 parent 11ab359 commit 009b413

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

data/duke.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ T | 1 | read book
22
D | 1 | return book | 2pm | 2020-02-01
33
D | 0 | submit code | 5pm | 2020-01-30
44
E | 0 | meeting | 8am | 2020-01-30
5-
T | 0 | nap
5+
T | 0 | nap
66
E | 0 | meeting | 1pm | 2020-02-01
77
D | 0 | tutorial | 2pm | 2020-02-02

src/main/java/Duke.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ public Duke(String filePath) {
1515
// following code from module website
1616

1717
ui = new Ui();
18-
storage = new Storage(filePath);
1918
parser = new Parser();
2019

2120
try {
21+
storage = new Storage(filePath);
2222
tasks = new TaskList(storage.load());
2323
} catch (DukeException e) {
2424
ui.showError(e);
@@ -28,7 +28,7 @@ public Duke(String filePath) {
2828

2929
public void run() {
3030
// following code from module website
31-
31+
3232
ui.greet();
3333

3434
boolean isExit = false;

src/main/java/META-INF/MANIFEST.MF

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: Duke
3+

src/main/java/duke/pack/Storage.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@ public class Storage {
1212
protected String filePath;
1313
protected File file;
1414

15-
public Storage(String filePath) {
15+
public Storage(String filePath) throws DukeException {
1616
this.filePath = filePath;
17+
18+
// file creation following code from
19+
// https://stackoverflow.com/questions/6142901/how-to-create-a-file-in-a-directory-in-java/6143076#6143076
1720
file = new File(filePath);
21+
try {
22+
file.getParentFile().mkdirs();
23+
file.createNewFile();
24+
} catch (IOException e) {
25+
throw new DukeException(" Oh no, file could not be created!\n");
26+
}
1827
}
1928

2029
public ArrayList<Task> load() throws DukeException {

0 commit comments

Comments
 (0)