I am trying to store result of some computations which I have stored in memory in HashMap
and a List
. Is there a way to store and load these data structures on disk so that I don't have to repeat this process over and over again?
EDIT
pickle
in python
and not an external dependency. Both List
and HashMap
(as well as other collections) are Serializable
in Scala, which means that standard Java serialization mechanisms can be applied to them.
You can store the objects by creating an ObjectOutputStream
and calling its writeObject(obj)
method.
The same applies for reading objects through an ObjectInputStream
and its readObject()
method.
The objects in the collections to read/write are also expected to be Serializable
, so if it's not yet the case, you'll need to make them implement the interface.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.