posted 14 years ago
I am able to save file onto disc. How do I make Save menu, so that it does not open JFileChooser, if I want to save something already loaded file. I am using netbeans. Here is my code to save a file:
private void mnuSaveAsActionPerformed(java.awt.event.ActionEvent evt) {
// Save the ArrayList and its object with their data as binary file
myChoice = new JFileChooser();
myChoice.showSaveDialog(this);
path = myChoice.getSelectedFile().getPath();
try
{
ObjectOutputStream outstream = new ObjectOutputStream(
new FileOutputStream(path));
outstream.writeObject(myList);
//dataDisplay.append("Array written to disk file;" +path + '\n');
outstream.close();
JOptionPane.showMessageDialog(null,"Your file is saved successfully" );
}
catch(IOException err1)
{
JOptionPane.showMessageDialog(null,"Sorry, " + err1.getMessage());
}
}