problem writing more than one string of data to a text file
hello.
i am trying to write data to a text file using JTextField. i got one error when i compiled the program (both error + code are shown below). how do i get rid of this error?
-jGRASP exec: javac -g E:\cp4bproject\PlaceOrder.java
PlaceOrder.java:54: cannot find symbol
symbol : method append(java.lang.String)
location: class java.io.File
file.append(text);
^
1 error
-jGRASP wedge2: exit code for process is 1.
-jGRASP: operation complete.
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
import java.io.*;
publicclass PlaceOrderextends JFrame{
JPanel pnlText, pnlBody, pnlFooter;
JButton btnPlaceOrder;
JButton btnReturnToOrderSystem;
JLabel jl;
JTextField jtf;
Container contentpane;
public PlaceOrder(){
super("Place Order");
contentpane = getContentPane();
contentpane.setLayout(new BorderLayout());
pnlText =new JPanel();
pnlBody =new JPanel();
pnlFooter =new JPanel();
jl =new JLabel("Text to save to file:");
btnPlaceOrder =new JButton("Place Order");
btnReturnToOrderSystem =new JButton("Return to Order System Menu");
pnlText.add(jl);
jtf =new JTextField(60);
pnlBody.add(jtf);
pnlFooter.add(btnPlaceOrder);
pnlFooter.add(btnReturnToOrderSystem);
contentpane.add(pnlText,BorderLayout.NORTH);
contentpane.add(pnlBody,BorderLayout.CENTER);
contentpane.add(pnlFooter,BorderLayout.SOUTH);
pack();
setVisible(true);
btnPlaceOrder.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
String s =null;
//Write to file
try{
String text = jtf.getText();
String outputFileName ="Order.txt";
File file =new File(outputFileName);
FileWriter fw =new FileWriter(file,true);
FileOutputStream out =new FileOutputStream(outputFileName);
file.append(text);
out.close();
}
catch(java.io.IOException ex){
System.out.println("Cannot write to file");
}
//Clear text field
jtf.setText("");
}
});
btnReturnToOrderSystem.addActionListener(new ActionListener(){
publicvoid actionPerformed(ActionEvent e){
setVisible(false);
//OrderSystem os = new OrderSystem();
//os.setVisible(true);
}
});
}
publicstaticvoid main(String[] args){
new PlaceOrder();
}
}

