i have a method that saves an object to file :
public void Save()
{
if (canSave)
{
JFileChooser fileChooser = new JFileChooser();
if (fileChooser.showSaveDialog (this) == JFileChooser.APPROVE_OPTION)
{
ObjectOutputStream out;
try {
out = new ObjectOutputStream (new FileOutputStream (fileChooser.getSelectedFile ()));
out.writeObject(this.game);
out.close ();
}
catch (IOException ex) { }
JOptionPane.showMessageDialog(null, fileChooser.getSelectedFile(),
"game saved",JOptionPane.INFORMATION_MESSAGE);
}
canSave = false;
}
else
JOptionPane.showMessageDialog(null,"cannot save game","save error",
JOptionPane.ERROR_MESSAGE);
}
how can i make it save files with an extension? for example: s.myfile
and the same question about opening files with extension.