File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package duke ;
22
3+ import java .io .UnsupportedEncodingException ;
4+ import java .net .URLDecoder ;
5+
36public class Duke {
47 private Storage taskStorage ;
58 private Storage contactStorage ;
@@ -9,8 +12,8 @@ public class Duke {
912 private ContactList contactList ;
1013
1114 public Duke () {
12- this .taskStorage = new Storage ("C:/Users/Jeremias/Documents/GitHub/ip/data/" , "task.txt" );
13- this .contactStorage = new Storage ("C:/Users/Jeremias/Documents/GitHub/ip/data/" , " contact.txt" );
15+ this .taskStorage = new Storage ( "task.txt" );
16+ this .contactStorage = new Storage ("contact.txt" );
1417 this .ui = new Ui ();
1518 this .parser = new Parser ();
1619 this .tasks = taskStorage .loadTaskList ();
@@ -115,4 +118,15 @@ public String getResponse(String input) {
115118 return ui .getError (e );
116119 }
117120 }
121+
122+ public static String getPath () {
123+ String path = Duke .class .getProtectionDomain ().getCodeSource ().getLocation ().getPath ();
124+ String decodedPath = null ;
125+ try {
126+ decodedPath = URLDecoder .decode (path , "UTF-8" );
127+ } catch (UnsupportedEncodingException e ) {
128+ e .printStackTrace ();
129+ }
130+ return decodedPath ;
131+ }
118132}
Original file line number Diff line number Diff line change 44import java .io .File ;
55import java .io .FileWriter ;
66
7+ import java .io .UnsupportedEncodingException ;
78import java .time .LocalDateTime ;
89import java .time .format .DateTimeFormatter ;
910
@@ -13,8 +14,8 @@ public class Storage {
1314 private final String filePath ;
1415 private final String fileName ;
1516
16- public Storage (String filePath , String fileName ) {
17- this .filePath = filePath ;
17+ public Storage (String fileName ) {
18+ this .filePath = Duke . getPath () ;
1819 this .fileName = fileName ;
1920 }
2021
You can’t perform that action at this time.
0 commit comments