复制代码
- //:Alien.java
- //Aserializableclass
- importjava.io.*;
- publicclassAlienimplementsSerializable{
- }///:~
复制代码
- //:FreezeAlien.java
- //Createaserializedoutputfile
- importjava.io.*;
- publicclassFreezeAlien{
- publicstaticvoidmain(String[]args)
- throwsException{
- ObjectOutputout=
- newObjectOutputStream(
- newFileOutputStream("file.x"));
- Alienzorcon=newAlien();
- out.writeObject(zorcon);
- }
- }///:~
复制代码
- //:ThawAlien.java
- //Trytorecoveraserializedfilewithoutthe
- //classofobjectthatsstoredinthatfile.
- packagec10.xfiles;
- importjava.io.*;
- publicclassThawAlien{
- publicstaticvoidmain(String[]args)
- throwsException{
- ObjectInputStreamin=
- newObjectInputStream(
- newFileInputStream("file.x"));
- Objectmystery=in.readObject();
- System.out.println(
- mystery.getClass().toString());
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |