我有一個客戶端應用程序,有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
客戶端應用程序 –