Skip to content

Commit

Permalink
Fix Storage.java
Browse files Browse the repository at this point in the history
  • Loading branch information
koonweee committed Sep 12, 2020
1 parent bedb875 commit d6b9584
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ application {
}

shadowJar {
archiveBaseName = "duke"
archiveBaseName = "jarvis"
archiveClassifier = null
}

Expand Down
Empty file added data/data.txt
Empty file.
2 changes: 0 additions & 2 deletions data/duke.txt

This file was deleted.

2 changes: 1 addition & 1 deletion data/pointer.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
C:\School\CS2103\ip\data\tasks - Copy.txt
data/data.txt
2 changes: 0 additions & 2 deletions data/tasks - Copy.txt

This file was deleted.

2 changes: 0 additions & 2 deletions data/tasks.txt

This file was deleted.

13 changes: 12 additions & 1 deletion src/main/java/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ public class Storage {

Storage(String filePath) throws IOException {
//read data file path from filePath file
this.pointerFile = new File(filePath);
Path testPath = Paths.get(filePath);
File testFile = new File(filePath);
if (testFile.exists()) {
this.pointerFile = testFile;
} else {
Files.createDirectories(testPath.getParent());
Files.createFile(testPath);
this.pointerFile = new File(filePath);
}
BufferedReader br = new BufferedReader(new FileReader(this.pointerFile));
String dataFilePath = br.readLine();
loadFile(dataFilePath);
Expand All @@ -29,6 +37,9 @@ File load() {
}

public void loadFile(String filePath) throws IOException {
if (filePath == null) {
filePath = "data/data.txt";
}
Path testPath = Paths.get(filePath);
File testFile = new File(filePath);
if (testFile.exists()) {
Expand Down

0 comments on commit d6b9584

Please sign in to comment.