//序列化
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;
}
序列化及反序列化
·86 字·1 分钟·
loading
·
loading
·
·
代码块
Java代码
Java代码 - 点击查看当前系列文章
§
序列化及反序列化 「 当前文章 」
Java代码 - 点击查看当前系列文章
§
序列化及反序列化 「 当前文章 」