Si si, questo e' abbastanza chiaro, ma non capisco bene il funzionamento.
Per esempio qui cerco di serializzare semplicemente un intero ma ottengo un IOException sulla chiamata a "oos.defaultWriteObject()".
Il codice sembra corretto pero'.
codice:
static public <T> void main(String pp[]) throws IOException{
Tests test = new Tests("babbo", "natale");
try {
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("c:\\myFile.txt"));
test.writeObject(os);
ObjectInputStream is = new ObjectInputStream(new FileInputStream("c:\\myFile.txt"));
test.readObject(is);
}
catch (IOException ex)
{System.out.println("IOEx");}
catch (ClassNotFoundException ex)
{System.out.println("class");
}
catch (Exception ex)
{System.out.println("exc");
}
}
private void writeObject(ObjectOutputStream oos) throws IOException{
oos.defaultWriteObject();
oos.writeInt(2);
oos.flush();
oos.close();
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException{
in.defaultReadObject();
int i = in.readInt();
in.close();
}