我有一个客户端应用程序,有10个以上的类,每个有100多个组件需要跟踪。当程序运行时,用户输入数字,选择项目,选中复选框等。我需要想出一种方法来保存程序关闭时的所有数据输入,并且能够再次运行程序时抓取来自上一次的所有数据都运行。保存大量的动态用户输入
我已经看过序列化,但我需要保存的一些事情是不可序列化的,所以没有奏效。我也研究过SingleFrameApplication和会话存储,但只是徒劳。
写入文件会导致需要花费数小时繁琐的编码,并且可能效率低下。有没有人有任何想法可以解决这个毛茸茸的问题?
更新:
做什么@Home建议我做了以下内容:
public Main() throws FileNotFoundException {
initComponents();
//read the file
Read();
//...
}
private void formWindowClosing(java.awt.event.WindowEvent evt) {
try {
//write to the file, the program is closing
Write();
} catch (FileNotFoundException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void Read() throws FileNotFoundException {
try{
XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(new FileInputStream("test.xml")));
//set the JTabbedPane to what is in the file
tab = (JTabbedPane) decoder.readObject();
decoder.close();
}catch(Exception e){
//there was no test.xml file so create one
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("test.xml")));
encoder.writeObject(null);
encoder.close();
}
}
private void Write() throws FileNotFoundException {
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("test.xml")));
//clear all previous things in the file
encoder.flush();
//write the JTabbedPane into the file
encoder.writeObject(tab);
encoder.close();
}
这些变化都当我运行的程序是一个空白JTabbedPane中弹出后。任何人都可以解释为什么这是事实吗?
嗯,你是在谈论一个脂肪(丰富)客户端应用程序还是Web应用程序? – home
客户端应用程序 –