Mega Code Archive

 
Categories / Java Tutorial / File
 

Illustrates serialization and deserialization

import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; class shutdown {   public static void main(String[] args) throws ClassNotFoundException, IOException {     FileOutputStream fos = new FileOutputStream("objects.tmp");     ObjectOutputStream oos = new ObjectOutputStream(fos);     oos.writeObject("asdf");     oos.flush();     fos.close();          FileInputStream fis = new FileInputStream ("objects.tmp");       ObjectInputStream ois = new ObjectInputStream (fis);       String t = (String) ois.readObject ();       fis.close ();           } }