Here are the codes I just compiled in java and I am getting a java.lang.Class CastException ...
and my printstack is
I cannot understand properly what it means since I am now learning java serialisation.. I awould appreciate any help..
Code:
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.io.ObjectOutput; import java.io.ObjectOutputStream; import java.io.Serializable; import java.util.Date; public class test_serialisation implements Serializable{ /** * */ private static final long serialVersionUID = 1L; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub FileOutputStream f; try { f = new FileOutputStream("tmp"); ObjectOutput s = new ObjectOutputStream(f); s.writeObject("Today"); s.writeObject(new Date()); s.flush(); FileInputStream in = new FileInputStream("tmp"); ObjectInputStream ss = new ObjectInputStream(in); Object dt=(Object)ss.readObject(); Date dtt=((Date) dt); System.out.println(dtt); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
Code:
java.lang.ClassCastException: java.lang.String at test_serialisation.main(test_serialisation.java:33)
Comment