/** * **************************************************************** Saves the text object to the * file at the given filepath * * @param path of file * @return completion status **************************************************************** */ public boolean saveString(String filepath) { File savefile = new File(filepath); FileWriter savefilewriter; // Attempt to create the file writer try { savefilewriter = new FileWriter(savefile); } catch (IOException e1) { return false; } String retval = ""; // Print the unit data for (DVD dvd1 : listDVDs) { // For a game if (dvd1.isGame()) { retval += DateFormat.getDateInstance(DateFormat.SHORT).format(dvd1.getDatePurchased().getTime()) + ","; retval += DateFormat.getDateInstance(DateFormat.SHORT).format(dvd1.getDateDue().getTime()) + ","; retval += dvd1.getTitle() + ","; retval += dvd1.getCustomerName() + ","; retval += ((Game) dvd1).getConsole(); } // For a dvd else { retval += DateFormat.getDateInstance(DateFormat.SHORT).format(dvd1.getDatePurchased().getTime()) + ","; retval += DateFormat.getDateInstance(DateFormat.SHORT).format(dvd1.getDateDue().getTime()) + ","; retval += dvd1.getTitle() + ","; retval += dvd1.getCustomerName(); } // Add the new line character retval += "\n"; } // Attempt to write to the file and close it try { savefilewriter.write(retval); savefilewriter.close(); } catch (Exception e) { return false; } return true; }