12 - Java Serialization with file - Theory

preview_player
Показать описание
@backstreetbrogrammer

--------------------------------------------------------------------------------
Chapter 03 - Serialization with file
--------------------------------------------------------------------------------
It would be incredibly useful if an object could exist and hold its information even while the program wasn’t running.

Then, the next time we started the program, the object would be there, and it would have the same information or state it had the previous time the program was running.

Object serialization allows us to implement persistence. Persistence means that an object’s lifetime is not determined by whether a program is executing; the object lives in between invocations of the program. By taking a serializable object and writing it to disk (via file), then restoring that object when the program is re-invoked, we’re able to produce the effect of persistence.

Java Object ==| Stream of bytes ==| File
File ==| Deserialize from stream of bytes ==| Java Object

FileOutputStream class is used to write the serialized stream of bytes to file on the disk. This class is an output stream for writing data to a File and is meant for writing streams of raw bytes such as image data.

FileInputStream class is used to read the stream of bytes from the file. This class obtains input bytes from a file in a file system and is meant for reading streams of raw bytes such as image data.

#java #javadevelopers #javaprogramming #javaserialization
Рекомендации по теме