-3

I am using Netbeans in order to create a small project in which the user inputs details for ordering cardboard boxes. The user must enter a client name, a postcode, and dimensions of the box. From there by pressing a number of calculation buttons, the program calculates surface area, cubic capacity, the cost for a single box and the total cost of the order.

The issue that I am having is when the user confirms the order. I have set up a text file for the data to be stored in once the user presses the confirm order button but for some reason, instead of the data being added to previous order details, the program instead replaces the previous order with the current order. This means that I can only ever have one order in my textfile.

lee1983
  • 1
  • 2
  • Show use the code you have tried. Does it work? If not, do you get an error? Is the output not what you expect? How does it differ from the expected output? –  May 03 '15 at 12:45

1 Answers1

0

Here's how:

try {
    PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("myfile.txt", true)));
    out.println("the text to append to existing file");
    out.close();
} catch (IOException e) {
    e.printStackTrace();
}

This will append text to an existing file, and will leave the existing text in the file.

Check this for more information.

Community
  • 1
  • 1
Jonas Czech
  • 12,018
  • 6
  • 44
  • 65
  • Have just been given the answer from a friend, apparently i needed to add the word true to the following line . output = new ObjectOutputStream(new FileOutputStream(file,true)); – lee1983 May 03 '15 at 17:44