java - loop through a serialized file or check for contents -
i learned serialization , practicing it.i wanted check if object i'm serialize in file or not.i think can looping through file , check if contains object or not.but cant found way loop through it.
is there way loop through serialized file or check contents ?
objectstream not designed out of box, exact solution depends on size of data + exact requirements.
1) if data large, , business requirements expected evolve - i'd consider proper database. e.g. mongodb if you'd write entire complex objects in 1 go (and, post implies, transactions not required).
2) if stick objectoutputstream, consider exact file format - data retrieval depend on that. however, all solutions boil down loading data java object in memory, , searching there...:
a) small data, keep data in java list/map (or wrapper model object such phonebook), read/write entirely in 1 go. e.g. on application startup: read entire phonebook file (or initialize empty 1 if file missing/corrupt). search: search phonebook object in memory. update: update phonebook object write entirely file (in override mode). goes without saying 1 can add optimizations in-memory data structure, e.g. hashmap speed search.
b) there's optimization (a) allows append 1 record @ time without re-writing entire data, works append. not delete/update: appending objectoutputstream
c) more advanced ideas discussed in following link, imho feels half way writing own database...: object serialization , random access in java
Comments
Post a Comment