模块需求分析
备份模块,当入库失败时,将未入库的数据保存到本地文件中。
采集模块每隔一段时间会从文件中读取数据,读取结束后将当前行号或其他索引信息调用备份模块存在本地文件中,在下次读取时从本地文件中拿到索引,从指定位置继续读取内容。
核心功能实现
序列化对象到本地文件
Object o = ...;
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(fileName))) {
oos.writeObject(data);
} catch (Exception e) {
e.printStackTrace();
}
从本地文件反序列化
Object o = null;
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(fileName))) {
o = ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}