Package work;
Import Java.io.ByteArrayInputStream;
Import Java.io.ByteArrayOutputStream;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import Java.io.ObjectInputStream;
Import Java.io.ObjectOutputStream;
Import java.io.Serializable; public class Test {public static void main (string[] args) throws FileNotFoundException, IOException, CLASSNOTFOUNDEXCEP
tion {//TODO auto-generated method Stub box a=new box (); Serialized as a file that can be used to save ObjectOutputStream oos1=new ObjectOutputStream (New FileOutputStream ("c:\\users\\wind\\desktop\\
A.txt "));
Oos1.writeobject (a);
ObjectInputStream ois=new ObjectInputStream (New FileInputStream ("C:\\users\\wind\\desktop\\a.txt"));
Box b= (Box) ois.readobject ();
System.out.println (B.gettiji ());
Serialized as a string that can be used for network transport bytearrayoutputstream Byteos = new Bytearrayoutputstream ();
ObjectOutputStream oos2=new ObjectOutputStream (Byteos);
Oos2.writeobject (a); StringResualtstring=byteos.tostring ("iso-8859-1");//Character set cannot be modified ObjectInputStream ois2=new ObjectInputStream (new
Bytearrayinputstream (Resualtstring.getbytes ("iso-8859-1"));
Box c= (Box) ois2.readobject ();
System.out.println (C.gettiji ());
The class box implements SERIALIZABLE{//declaration interface, without implementing the concrete method int i,j,k;
Box () {i=1;
j=2;
k=3;
int Gettiji () {return i*j*k;
}
}