Kaffe and Serialization
Ivana Visconti Menna
iviscont at dcc.uchile.cl
Tue May 4 08:00:46 PDT 1999
Hi Everybody
I downloaded Kaffe and today I made my first test.
I have an example of Serialization that works fine, but with Kaffe
doesn't. Should I use anything especial?
Thanks in advance
Ivana
Here is the source code:
///////////////////////////////////////////////////////
import java.io.*;
import java.util.*;
class ObjectSerialization {
public static void main(String[] args) {
WR wr = new WR();
wr.write();
wr.read();
}
}
class WR {
FileOutputStream os = null;
ObjectOutput oo = null;
FileInputStream is = null;
ObjectInput oi = null;
WR() {};
// write an object
public void write() {
Date d = new Date();
try {
os = new FileOutputStream("SavedObject");
oo = new ObjectOutputStream(os);
} catch ( Exception e ) {
System.out.println(e);
System.out.println("WRITE: Unable to open stream
as an obj
ect stream");
}
try {
oo.writeObject("Today is: ");
oo.writeObject(d);
os.close();
} catch ( Exception e ) {
System.out.println(e);
System.out.println("Unable to write Objects");
}
// read an object
public void read() {
try {
is = new FileInputStream("SavedObject");
oi = new ObjectInputStream(is);
} catch ( Exception e ) {
System.out.println("READ: Unable to open stream
as an object stream");
}
Date d = null;
String str = null;
try {
str = (String)oi.readObject();
d = (Date)oi.readObject();
} catch ( Exception e ) {
System.out.println("Unable to read Object");
}
System.out.println("The String that was written is: " +
str);
System.out.println("The Date that was written is: " +
d);
}
}
////////////////////////////////////////////////////
More information about the kaffe
mailing list