Serializable+单立模式的问题

happyday4832 2005-11-06 12:14:21
我做的是一个包含图形信息的文件,目的是能保存,再读出来.(在GraghView Serialiable了.)
可是现在输入输出都没有异常,能保存成一个40k左右的文件,读不出来.
我在想是不是因为GraghView里面的getInstance是单立模式,所以不能初始化呢?/或者io写的有问题?
//输出
private void saveFile() {
JFileChooser chooser = new JFileChooser();
int state = chooser.showSaveDialog(MainFrame.this);
GraghView s= new GraghView();
File f = chooser.getSelectedFile();
try {
ObjectOutputStream out =
new ObjectOutputStream(new FileOutputStream(f,true));
out.writeObject(s);
out.flush();
out.close();
} catch(Exception e) {
e.printStackTrace();
}
}
}
//输入
private void openFile() {
JFileChooser chooser = new JFileChooser();
int state = chooser.showOpenDialog(MainFrame.this);
GraghView s= new GraghView();
File f = chooser.getSelectedFile();
try {
ObjectInputStream in =
new ObjectInputStream(new FileInputStream(f));
s =(GraghView)in.readObject();

in.close();
} catch(Exception e) {
e.printStackTrace();
}



}
}
//

...全文
41 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,629

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧