序列化及反序列化

//序列化
public static void serialization(List list,String file) throws IOException {
    File file1 = new File(file);
    ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream(file));
    for (Object o : list){
        outputStream.writeObject(o);
    }
    outputStream.flush();
    outputStream.close();
}
//反序列化
public static List deserialization(String file) throws IOException, ClassNotFoundException {
    File file1 = new File(file);
    List list = new ArrayList();
    ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
    Object o;
    while (true){
        try {
            o = inputStream.readObject();
        }catch (Exception e){
            break;
        }
        list.add(o);
    }
    inputStream.close();
    return list;
}