forked from nus-cs2113-AY2122S2/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add read/write functionalities such that users can load their own tas…
…k lists from their hard disks and save changes they made to their lists on their hard disks
- Loading branch information
chihyingho
authored and
chihyingho
committed
Mar 2, 2022
1 parent
5ee1827
commit 8d655bc
Showing
7 changed files
with
263 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
T|0|deadline | ||
D|0|eat lunc|noon | ||
D|0|lunc|tomorrow | ||
T|0|lunch | ||
T|0|lunch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.io.File; | ||
import java.io.FileNotFoundException; | ||
import java.util.Scanner; | ||
|
||
public class FileEditor { | ||
private static final String DIRECTORY = "data"; | ||
private static final String FILENAME = "duke.txt"; | ||
private static final String FILEPATH = DIRECTORY + File.separator + FILENAME; | ||
|
||
public static void updateFile(ArrayList<Task> tasks) throws IOException { | ||
FileWriter fw = new FileWriter(FILEPATH); | ||
for (Task task : tasks) { | ||
String taskToAppend = task.getDetails(); | ||
fw.write(taskToAppend + System.lineSeparator()); | ||
} | ||
fw.close(); | ||
} | ||
|
||
public ArrayList<String> readFileContents() throws IOException { | ||
File directory = new File(DIRECTORY); | ||
if(!directory.exists()) { | ||
directory.mkdir(); | ||
} | ||
File file = new File(DIRECTORY + File.separator + FILENAME); | ||
if(!file.exists()) { | ||
file.createNewFile(); | ||
} | ||
Scanner s = new Scanner(file); | ||
ArrayList<String> tasksFromFile = new ArrayList<>(); | ||
while (s.hasNextLine()) { | ||
tasksFromFile.add(s.nextLine()); | ||
} | ||
return tasksFromFile; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters