Revisions for ⁨saveData⁩

View the changes made to this paste.

unlisted ⁨1⁩ ⁨file⁩ 2020-09-17 20:36:17 UTC

saveData.java

@@ -0,0 +1,23 @@

+public boolean saveData(String filename) {
+        boolean wasSaveSuccessful = false;
+        BookReadNode bookReadNode = listHead;
+
+        try {
+            File file = new File(filename);
+            PrintWriter printWriter = new PrintWriter(file);
+
+            for (BookReadEntry bookReadEntry : bookReadNode.getBookReadEntryObj()) {
+                System.out.println("SAVING BOOK: " + bookReadNode.getBookReadEntryObj().getBookObj().getBookTitle());
+                printWriter.println(bookReadNode.getBookReadEntryObj().toFileFormat());
+            }
+
+            printWriter.flush();
+            printWriter.close();
+
+            wasSaveSuccessful = true;
+        } catch (FileNotFoundException fileNotFoundException) {
+            wasSaveSuccessful = false;
+        }
+
+        return wasSaveSuccessful;
+    }
\ No newline at end of file