saveData

Writes existing read log to file

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

saveData.java

Raw
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;
    }