Current location - Quotes Website - Personality signature - How to use serializable interfaces
How to use serializable interfaces
You must implement this interface to serialize the objects of this class and serialize the class into a byte stream. Serializable is a marked interface, so there is no need to override the method. For example.

This is all the input and output after serializing the objects of class T.

Import java.io. *;

Public class TestObjectIO {

Public static void main(String args[]) throws an exception {

T T = new T();

t . k = 8;

file output stream fos = new file output stream(" d:/share/Java/io/testobjectio . dat ");

object output stream OOS = new object output stream(fos);

OOS . writeobject(t);

OOS . flush();

OOS . close();

file inputstream fis = new file inputstream(" d:/share/Java/io/testobjectio . dat ");

ObjectInputStream ois = new ObjectInputStream (FIS);

T tReaded =(T)ois . read object();

system . out . println(treaded . I+" "+treaded . j+" "+treaded . d+" "+treaded . k);

}

}

Class t

Realize serializability

{

int I = 10;

int j = 9;

Double d = 2.3

Transient int k =15;

}