I am attempting to serialize multiple maps to one file so that I can retrieve them at a later time and rebuild all the values back into their original, distinct maps.
The maps are simple key/value pairs. In real-life usage there will only be about 10 distinct maps, with about 20 entries each, so performance isn’t a massive concern.
My original thoughts were to use the java Properties file approach, although this seems to only be suited for serializing one map to the file. I need to do multiple maps. Is there a way I can still use Properties file but specify a separator for different map’s values?
If this isn’t possible with Properties file, what would be the most convenient way of achieving what I want? I am hoping there is some predefined java utility methods for this sort of thing so that I don’t have to figure out my own file format and parsing/writing code.
Thanks.
For simply storing the maps, use the buildin java serialization (given your keys and values do implement java.io.Serializable).
Using ObjectOutputStream/ObjectInputStream you can serialize the data pretty easily, albeit the data will be stored in binary form.