The following is the code I am using to show the array on the screen with correct formatting:
public void output()
{
System.out.println("Item Cost Quantity Description" );
System.out.println("==================================================" );
for (int outputIndex = 0; outputIndex < countItems; outputIndex++)
{
System.out.printf("%9.2f %10d %s\n", items[outputIndex].getCost(), items[outputIndex].getQuantity(), items[outputIndex].getDescription());
}
System.out.println("==================================================" );
System.out.println(" ");
}
Which works just fine. However, when I use similar code for outputting to file it fails to write anything and instead saves a blank page in the file:
public void save() throws IOException
{
FileWriter fwriter = new FileWriter("shopping.dat");
PrintWriter outputFile = new PrintWriter(fwriter);
for (int saveIndex = 0; saveIndex < countItems; saveIndex++)
{
outputFile.printf("%9.2f %10d %s\n", items[saveIndex].getCost(), items[saveIndex].getQuantity(), items[saveIndex].getDescription());
}
upToDate = true;
}
Please help me???


Sign In
Create Account

Back to top









