I have a DVD inventory record program that creates a DAT file if none exists and then stores the user input. As long as the program is running the user may then advance one record at a time (forward or back) through the files, skip at anytime to the first record or the last, and edit any file. Once the program closes I can open the file and view all of the saved files and they are there. The problem I have is that the next time the program is ran all that displays is the default values I established in the constructor (it is not pulling up my previously saved data). While my program meets all of my instructors requirements, it does not work in a useful manner. here are code snippets from my display and save sections.
//display
public void displayDVD() {
txt.setText("DVD Details:\n");
txt.append("Item number: " + inv.get(currentDisplay).getDvdItem() + "\n");
txt.append("DVD name: " + inv.get(currentDisplay).getDvdTitle() + "\n");
txt.append("Units in stock: " + inv.get(currentDisplay).getDvdStock() + "\n");
txt.append("Price: $" + String.format("%.2f",inv.get(currentDisplay).getDvdPrice()) + "\n");
txt.append( "Runtime in minutes: " + inv.get(currentDisplay).getRuntime() + "\n");
txt.append("Total value: $" + String.format("%.2f",inv.get(currentDisplay).value()) + "\n");
txt.append("Fee: $" + String.format("%.2f",inv.get(currentDisplay).fee()) + "\n\n");
txt.append("Total value: $" + String.format("%.2f",inv.value()));
}
and
public void save() {
save(true);
}
// save it to C:\data\inventory.dat
public void save(boolean saveagain) {
try {
BufferedWriter w = new BufferedWriter(new FileWriter("c:\\data\\inventory.dat"));
for (int i = 0; i < size(); i++) {
DVDRuntime dvd = get(i);
w.write("Item number: " + dvd.getDvdItem() + "\n");
w.write("Item name: " + dvd.getDvdTitle() + "\n");
w.write("Items in stock: " + dvd.getDvdStock() + "\n");
w.write("Runtime: " + dvd.getRuntime() + "\n");
w.write("Price: $" + dvd.getDvdPrice() + "\n");
w.write("Fee: $" + dvd.fee() + "\n");
w.write("Value (including the fee): $" + dvd.value() + "\n");
w.newLine();
}
// total value of it
w.write("Total fee: $" + (value() - value()/1.05) + "\n");
w.write("Total value (including the fee): $" + value() + "\n");
w.close();
} catch (Exception ex) {
if (saveagain) {
new File("c:\\data\\").mkdir(); // make it if it wasn't there!
save(false); // if it doesn't work now, we have a big problem!
}// end IF
}// end catch
}//end method save
If more code is needed I can post it Thanks