(对象的序列化)在下列程序的空白处,应填入的正确选项是________。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); } }}
举一反三
- 阅读程序,根据要求填空使程序能正确运行。 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.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()); } }
- 关于包的导入,以下选项正确的是()。 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. 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); } }
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }