-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathStorage.java
More file actions
48 lines (42 loc) · 1.23 KB
/
Storage.java
File metadata and controls
48 lines (42 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package duke;
import duke.handler.Parser;
import duke.tasks.Deadline;
import duke.tasks.Event;
import duke.tasks.Task;
import duke.tasks.TaskList;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Scanner;
public class Storage {
private static String STORAGE_PATH;
private static final int MARK_INDEX = 2;
public Storage(String storagePath) {
STORAGE_PATH = storagePath;
}
public TaskList load() {
TaskList tasks = new TaskList();
Scanner dataReader = null;
try{
File file = new File(STORAGE_PATH);
file.getParentFile().mkdirs();
file.createNewFile();
dataReader = new Scanner(file);
while (dataReader.hasNextLine()) {
Task task = Parser.parseFromData(dataReader.nextLine());
tasks.addTask(task);
}
return tasks;
} catch (IOException e) {
System.out.println("File did not load");
} finally {
dataReader.close();
}
return tasks;
}
}