198255nihao
发贴: 6
积分: -3
|
于 2006-02-22 15:38
import java.io.*;
public class SerializationDemo { public static void main(String[] args) throws Exception { try { MyClass object1 = new MyClass("Hello",-7,2.7e10); System.out.println("object1 : "+object1); /*object1.s=object1.s+" Fuck you"; object1.d=object1.d+10; object1.i=object1.i+20;*/ FileOutputStream fos = FileOutputStream("serial"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(object1); oos.flush(); oos.close(); } catch (Exception e) { System.out.println("Exception during serialization : "+e); System.exit(0); } try { MyClass object2 ; FileInputStream fis = FileInputStream("serial"); ObjectInputStream ois = ObjectInputStream(fis); object2=(MyClass)ois.readObject(); ois.close(); System.out.println("Object2 : "+object2); } catch (Exception e) { System.out.println("Exception during deserialization : "+e); System.exit(0); } } }
class MyClass implements Serializable { String s; int i; double d; public MyClass(String s,int i,double d) { this.s=s; this.i=i; this.d=d; } public String toString() { return "s= "+s+" i= "+i+" d= "+d; } }
提示 cannot find symbol 到底是什么错误啊。
|