请教关于Object流的问题,Externalizable接口的应用测试
import *;public class TestObject {
public static void main(String[] args){
TestSer ts = new TestSer();
TestExt te = new TestExt();
try{
FileOutputStream fos = new FileOutputStream("D:/JAVA/testStream/object.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(te);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream("D:/JAVA/testStream/object.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
te = (TestExt)ois.readObject(); //**********************
ois.close();
} catch(FileNotFoundException e){
System.out.println("FileNotFoundException");
e.printStackTrace();
System.exit(-1);
} catch(IOException e){
System.out.println("IOException");
e.printStackTrace();
System.exit(-1);
} catch(ClassNotFoundException e){
System.out.println("ClassNotFoundException");
e.printStackTrace();
System.exit(-1);
}
}
}
//继承接口测试类
class TestExt implements Externalizable {
String s = "hello";
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
s = (String)in.readObject();
}
public void writeExternal(ObjectOutput out) throws IOException {
out.writeObject(s);
}
}
-----------------------------------------------------------------------------------------------------------
注意上面程序用注释***********标记的地方,那里抛出了
想了很久也不知道为什么。求大神们解答。。。
谢谢