Cov txheej txheem:

Yuav ua li cas koj deserialize ib yam khoom hauv Java?
Yuav ua li cas koj deserialize ib yam khoom hauv Java?

Video: Yuav ua li cas koj deserialize ib yam khoom hauv Java?

Video: Yuav ua li cas koj deserialize ib yam khoom hauv Java?
Video: Yuav Ua li Cas Koj Thiaj Muaj Nyiaj 2024, Hlis ntuj nqeg
Anonim

Serialization thiab Deserialization hauv Java nrog piv txwv. Serialization yog ib tug mechanism ntawm converting lub xeev ntawm ib tug khoom nyob rau hauv ib tug byte kwj. Deserialization yog cov txheej txheem thim rov qab uas cov kwj byte siv los tsim qhov tseeb Java object hauv nco. Qhov no mechanism yog siv los txuas ntxiv mus khoom.

Yog li ntawd, ua li cas koj serialize ib yam khoom hauv Java?

Rau serialize ib yam khoom txhais tau tias hloov nws lub xeev mus rau ib tug byte kwj thiaj li hais tias cov byte kwj yuav reverted rov qab mus rau hauv ib daim qauv ntawm cov khoom . A Java object yog serializable yog tias nws cov chav kawm lossis ib qho ntawm nws cov superclasses siv ob qho tib si java ua . io ib. Serializable interface los yog nws subinterface, java ua.

Koj nyeem cov khoom hauv Java li cas? Yuav Ua Li Cas Nyeem Ib Yam Ntawm Cov Ntaub Ntawv hauv Java

  1. Qhib FileInputStream rau cov ntaub ntawv uas koj tau khaws cia rau.
  2. Qhib ObjectInputStream rau saum FileInpoutStream.
  3. Siv readObject txoj kev ntawm ObjectInputStream chav kawm nyeem Object los ntawm cov ntaub ntawv.
  4. Cov txheej txheem saum toj no rov qab ib qho Object ntawm hom Object.

Kuj Paub, koj ua li cas deserialize cov npe hauv Java?

Ntawm no yog ib qho piv txwv tiav. Cov no yog cov kauj ruam:

  1. Tsim Class Item() uas siv Serializable.
  2. Hauv Main - Tsim 2 Yam Khoom.
  3. Ntxiv rau ArrayList.
  4. Serialize lub ArrayList. Checkout cov ntaub ntawv kom pom bytestream ntawm ib qho khoom. (Cov duab hauv qab no)
  5. Deserialize cov bytestream los ntawm tib cov ntaub ntawv kom pom Object.

Lub hom phiaj ntawm serialization hauv Java yog dab tsi?

Yam khoom Serialization yog txheej txheem siv los hloov lub xeev ntawm ib yam khoom mus rau hauv byte kwj, uas tuaj yeem txuas ntxiv mus rau hauv disk / ntaub ntawv lossis xa tawm hauv lub network mus rau lwm yam kev khiav haujlwm. Java tshuab virtual. Cov txheej txheem thim rov qab ntawm kev tsim ib yam khoom los ntawm byte kwj hu ua deserialization.

Pom zoo: