Mega Code Archive

 
Categories / Java / File Input Output
 

Create a serialized output file

// : c12:FreezeAlien.java // Create a serialized output file. // {Clean: X.file} // From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002 // www.BruceEckel.com. See copyright notice in CopyRight.txt. import java.io.FileOutputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; public class FreezeAlien {   // Throw exceptions to console:   public static void main(String[] args) throws Exception {     ObjectOutput out = new ObjectOutputStream(         new FileOutputStream("X.file"));     Alien zorcon = new Alien();     out.writeObject(zorcon);   } } ///:~ class Alien implements Serializable { } ///:~