62,623
社区成员
发帖
与我相关
我的任务
分享
public void saveFile()
{
fileChooser = new JFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
int result = fileChooser.showSaveDialog(this);
if (result == JFileChooser.CANCEL_OPTION) {
return;
}
else {
File fileName = fileChooser.getSelectedFile();
fileName.canWrite();
if (fileName == null || fileName.getName().equals("")) {
JOptionPane.showMessageDialog(fileChooser, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
}
else {
try {
fileName.delete();
FileOutputStream fos = new FileOutputStream(fileName);
output = new ObjectOutputStream(fos);
drawings record;
output.writeInt(index);
for (int i = 0; i < index; i++) {
drawings p = itemList[i];
output.writeObject(p);
output.flush();
}
output.close();
fos.close();
}
catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
}