Serializable+单立模式的问题
我做的是一个包含图形信息的文件,目的是能保存,再读出来.(在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();
}
}
}
//