从对象流中读取对象,请在下面横线处填写代码完成此程序。 import java.util. *; import java. io. *; public class UnSerializeDate { date d = null; UnSerializeDate ( ) { try { FileInputStream f1 = new FileInputStream("date.ser"); d = (Date) s. readobject (); f1,close(); } catch (Exceptin e) { e. printStackTrace (); } } public static main(String args [] ) { System.out.println("The date read is: "+ a.d.toString()); } }
举一反三
- 阅读下列程序,请写出该程序的功能。 import java. util.*; public class Class1{ public static void main(Srting args[]){ Date date1=new Date(); System. out. println (datel); String t=datel.toString(); int endPos=t.indexOf(`C'); t=t.substring(11,endPos); System. out println(t); } }
- 阅读程序,根据要求填空使程序能正确运行。 import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Demo3 { public static void main(String[] args) { Date today = new Date(); String pattern = "yyyy年MM月dd日"; SimpleDateFormat sdf = new SimpleDateFormat(_______________); String str = ________________ System.out.println(str); } }
- 下面代码的运行结果为:( ) import java.io.*; import java.util.*; public class foo{ public static void main (String[] args){ String s; System.out.println("s=" + s); } }
- 关于包的导入,以下选项正确的是()。 A: import java.*; B: import java.util.Date; Date today = new Date(); C: import java.*.*; D: import java.util.*; import java.sql.*; Date today = new Date();
- (对象的序列化)在下列程序的空白处,应填入的正确选项是________。import java. io.*;public class ObjectStreamTest{ public static void main(String args[]) throws IOException{ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(serial.bin)); java.util.Date d=new java.util.Date(); oos.______(d); ObjectInputStream ois = new ObjectInputStream (new FileInputStream(serial.bin)); try{ java.util.Date restoredDate=(java.util.Date)ois.readObject(); System.out.println(read object back from serial.bin file:+ restoredDate); }catch(ClassNotFoundException cnf){ System.out.println(class not found); } }}