Serialization

v Serialization overview:

  - Serialization is the process of storing the state of the object in a specific storage medium. That is, the process of converting the state of the object into a transmission format!

  - During the serialization process, the common members of the object, Private member, (includes the class name). Convert it to a byte stream, and then write the byte stream to the data stream and store it in the storage medium;
  - The storage medium usually refers to a file

  - The meaning of using serialization is to serialize Java objects After the serialization, it can be converted into a byte sequence (which can be saved on the hard disk), and these serialized objects are stored in binary state. (Achieving platform independence)

   In Java, only java.io.Serializable is implemented. Objects of interface classes can only be serialized!

----------------------------------------- ---------------------------
    v Serialization The

  serialization mechanism can convert the serialized java object into a byte sequence. This process Need to use IO stream to achieve!

  The steps of serialization are very simple and can be divided into 2 big steps:

  (1) Create an object output stream (ObjectOutputStream), which can wrap an output stream of other types, such as FileOutputStream.
   ObjcetOutputStream oos = new ObjcetOutputStream (new FileOutputStream("E:/shu.txt"))
    creates an object output stream and wraps a file output stream;

  (2) Write the object through the writeObjcet() method of the object output stream, that is, serialize the object and output
      steps
         [1] Create a class that implements the Serializable interface
         [2] Introduce related classes
         [3] Create an object output stream
         [4] Call the writerObjcet() method to write the object to a file
         [5] Close the object output stream

-------- -------------------------------------------------- ----------- v Deserialization Deserialization   is the process of rebuilding data from a specific storage medium and building an object. Through deserialization, the object information stored on the file can be read out, and then reconstructed as an object   . The steps of deserialization are roughly two steps:     (1) Create an object input stream (ObjectInputStream), which can wrap an other Types of input streams, such as FileInputStream     (2) Read the object through the readObject() method of the object input stream. This method returns an object of type object , if the program knows the type of the java object, it can cast the object to the real type;









Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326403135&siteId=291194637