2014-12-02 96 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.

您的序列化类的每一个成员都有可序列化,也被序列化。

您是否考虑将保健中心的信息保存在数据库中?每次信息变化时,使用数据库也会保持保存或读取所需的信息量最小。 :)