Save As/Load Dialog
In my program I write some stuff to a JTextArea, and I have a save button. When press it, it saves to a default text file. But I want a Save As dialog a la any windows prgoram to pop up, enabling to choose file name and directories etc etc. I also want to be able to do the same for loading. Can you please help me? This is how my code for saving looks right now:
JButton button2 =new JButton("Save");
button2.addActionListener(
new ActionListener()
{
publicvoid actionPerformed(ActionEvent e)
{
//JOptionPane.showMessageDialog(parentComponent, "BUTTON PRESSED!");
FileOutputStream out;
PrintStream p;
try{// Create a new file output stream
// connected to "myfile.txt"
out =new FileOutputStream("saveddata.txt");// Connect print stream to the output stream
p =new PrintStream( out );
p.println ( lolarea.getText() );
p.close();
}
catch (Exception ex){ System.err.println ("Error writing to file");
}
}
});

