2014-12-02 88 views
1

我是新來這個論壇,但也對Java,所以如果我的問題似乎很愚蠢,請原諒。保存並讀取arraylist的arraylist類

對於一個項目,我要爲健康中心建立一個程序,所以我決定去像這樣:

public class Laboratory implements Serializable { 
protected static String labName; 
protected static ArrayList<People> listPeople; 
protected static ArrayList<File> listFile; 

棘手的部分是,每一個目標文件也是由一個ArrayList的分析...

public class File { 
protected String loginPatient; 
private ArrayList<Analyse> listAnalyses; 

我要保存它,並讓每一個ArrayList中listPeople和ArrayList中的每個文件listfile中會保存每次的程序退出並加載每次節目開始讀它。

所以,正如你所看到的,我想使用Serializable,但我沒有得到如何使用它在整個類實驗室,我只看到它ArrayList。這是否是最好的方式,如果是這樣,如何? 此外,如果一個數組列表是由另一個數組列表組成的,可序列化的工作?

再次感謝您的答案,如果您有任何問題,請告訴我! 這可能不是這個程序的最佳工作方式,因此歡迎任何建議!的interface Serializable :)

回答

0

描述說Serializability of a class is enabled by the class implementing the java.io.Serializable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

您的序列化類的每一個成員都有可序列化,也被序列化。

您是否考慮將保健中心的信息保存在數據庫中?每次信息變化時,使用數據庫也會保持保存或讀取所需的信息量最小。 :)