Search code examples
javafileobjectfileinputstreamfileoutputstream

What is the benefit of writing an object to a file?


I understand we can do this with file input and output, but why would we want to do this?


Solution

  • It is simply called persistence.

    You nailed it: you want to be able to store information (for example after intensive computations) in a way that survives the lifetime of the current JVM process.

    In that sense serialization is a (poor) version of database storage.

    But of course, that comment is correct: this does not prevent the creation of objects. It is a mechanism to resurrect previous state into "new" objects.