HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"The Data Series: Object Serialization"
Vol. 3, Issue 3, p. 68

	

Listing 1: Saving string and date object.
  
String tText = ěPlease save me!î;  
Date   tWhen = new Date();  

FileOutputStream     FS = new FileOutputStream("saveme.txt");  
ObjectOutputStream   OS = new ObjectOutputStream(FS);  
OS.writeObject( tText );  
OS.writeObject( tWhen );  
OS.flush();  

Listing 2: Main methods of ObjectOutput interface.
  
public interface ObjectOutput extends DataOutput  
{  
  public void writeObject(Object obj) throws IOException;  
  public void write(int b) throws IOException;  
  public void write(byte b[]) throws IOException;  
  public void write(byte b[], int off, int len) throws IOException;  
  public void flush() throws IOException;  
  public void close() throws IOException;  
}  

Listing 3.
  
String tText;  
Date   tWhen;  

FileIntputStream     FS = new FileInputStream("saveme.txt");  
ObjectOutputStream   IS = new ObjectInputStream(FS);  
tText                   = (String)IS.readObject();  
tWhen                   = (Date)IS.readObject();  

Listing 4: Implementing java.io.Serializable interface.
  
public class myClass implements java.io.Serializable  
{  
  String Name = ěî;  
  int age = 39;  

  public class myClass(){  
    Name = ěCeriî;  
    age  = 19;  
  }  
}  
  
      
 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.