下面程序段是从对象流中读取对象,请将程序补充完整。
import java.util. *;
import java.io. *;
public class UnSerializaDate
Dated=null;
UnSerializaDate()
try
FilelnputStream f=new FileInputStream("date.ser");
ObjectInputStream s=new ObjectInputStream(f);
f.close();
catch(Exceptione)
e.printStackTrace();
public static void main(String args[])
public static void main(String args[])
UnSerializaDate a=new UnSerializaDate();
System.out.println("The date read is:"+a.d.toString());
参考答案:d=(Date)s.readObject()
解析: 本题考查对象流的读取。对象输入流ObjectInputStream的对象s是以一个文件输入流为基础构造的。程序中使用ObjectInputStream的readObject()方法从对象流s中读取Date类型的对象。读该对象时要按照它们写入的顺序读取,因为readObject()返回的是Object类型的对象,所以程序中使用了强制类型转化,将所读取对象的类型转换为Date类型。