单选题 在下列程序的空白处,应填入的正确选项是______。
import Java.io*;
pulilc class Obj ectStreamTest{
publilc static void main(string args[]) throws IOException{
ObjectOutputStream oos=new ObjectOutputStream
(new FileOutputStream("serial.bin"));
Java until.Date d=new Java.until Date();
oos (d);
ObjectInputStream ois=
new ObjectInputStream(new FileOutputStream("serial.bin"));
try{
java until.date restoredDate=
(Java.until.Date)ois.readObject();
System.out.println
("read object back from serial.bin file:"
+restoredDate);
}
catch(ClassNotFoundException cnf) {
System.out.println("class not found");
}
}
【正确答案】 D
【答案解析】[解析] java.io包中,提供了ObjectInputstream和ObjectOutputStream将数据流功能扩展至可读写对象。在ObjectInpulStream中用readObject()方法可以直接读取一个对象,ObjetOutputstream中用writeObject()方法可以直接将对象保存到输出流中。因此,本题的正确答案是D。