欢迎来到天天文库
浏览记录
ID:27680364
大小:1.69 MB
页数:95页
时间:2018-12-02
《对象序列化和持久化》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、对象序列化和持久化ObjectSerializationandPersistence2021/9/8InstituteofComputerSoftwareNanjingUniversity1摘要对象序列化对象持久化LanguagelevelDatabasesHibernate2021/9/8InstituteofComputerSoftwareNanjingUniversity2摘要对象序列化对象持久化LanguagelevelDatabasesHibernate2021/9/8InstituteofComputerSoftwareNa
2、njingUniversity3摘要对象序列化对象持久化LanguagelevelDatabasesHibernate2021/9/8InstituteofComputerSoftwareNanjingUniversity4ObjectSerializationWhyWhatHow2021/9/8InstituteofComputerSoftwareNanjingUniversity5JavaObjectSerialization--WhySerializationisusedforlightweightpersistenceandfo
3、rcommunicationviasocketsorRemoteMethodInvocation(RMI).2021/9/8InstituteofComputerSoftwareNanjingUniversity6JavaObjectSerialization--ExamplepublicclassClient{publicstaticvoidmain(Stringargs[]){try{//CreateasocketSocketsoc=newSocket(InetAddress.getLocalHost(),8020);OutputS
4、treamo=soc.getOutputStream();ObjectOutputs=newObjectOutputStream(o);s.writeObject("Today'sdate");s.writeObject(newDate());s.flush();s.close();}catch(Exceptione){System.out.println(e.getMessage());System.out.println("Errorduringserialization");System.exit(1);}}}2021/9/8In
5、stituteofComputerSoftwareNanjingUniversity7JavaObjectSerialization--ExamplepublicclassServer{publicstaticvoidmain(Stringargs[]){ServerSocketser=null;Socketsoc=null;Stringstr=null;Dated=null;try{ser=newServerSocket(8020);soc=ser.accept();InputStreamo=soc.getInputStream();
6、ObjectInputs=newObjectInputStream(o);str=(String)s.readObject();d=(Date)s.readObject();s.close();System.out.println(str);System.out.println(d);}catch(Exceptione){System.out.println(e.getMessage());System.out.println("Errorduringserialization");System.exit(1);}}}2021/9/8I
7、nstituteofComputerSoftwareNanjingUniversity8JavaObjectSerialization--ExampleWritingtoanobjectstream2021/9/8InstituteofComputerSoftwareNanjingUniversity9//Serializetoday'sdatetoafile.FileOutputStreamf=newFileOutputStream("tmp");ObjectOutputs=newObjectOutputStream(f);s.wri
8、teObject("Today");s.writeObject(newDate());s.flush();JavaObjectSerialization--ExampleReadingfromanobjec
此文档下载收益归作者所有