-
GUI to save to file
Greetings Gents,
I am new in this professional forums and I would like to help me !!
I am trying to created interface to save input data to file. Interface done however I am facing problem with saving data to file every time it save over old one.
code I am using
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
PrintWriter fileOut = new PrintWriter(new FileWriter("filename.txt"));
fileOut.append(jTextField1.getText());
fileOut.append(jTextField2.getText());
fileOut.append(jTextField3.getText());
fileOut.append(jTextField4.getText());
fileOut.append(jTextField5.getText() );
fileOut.close(); // Close the output stream after all output done.
JOptionPane.showMessageDialog(null, "Student record saved seccussecfully !!");
jTextField1.setText("");
jTextField2.setText("");
jTextField3.setText("");
jTextField4.setText("");
jTextField5.setText("");
}
catch (IOException ioe)
{
System.out.println("Exception ");
}
// TODO code application logic here
return;
I need output like
Fname/lastname/Telephone/ID/addree
Fname/lastname/Telephone/ID/addree
-
Re: GUI to save to file
Please use [code] tags [/code] when posting code.
Look at the available constructors for FileWriter.
One of them allows you to append.