更多“单选题阅读下列Java语句:ObjectOutputStream out=new ObjectOutputStream(new ______(employee.dat));在下画线处,应填的正确选项是(  )。A FileB FileWriterC FileOutputStreamD OutputStream”相关问题
  • 第1题:

    Java 中处理字符流的抽象类是( )。

    A.OutputStream和InputStream

    B.Reader和Writer

    C.ObjectOutputStream和ObjectlnputStream

    D.InflaterlnputStream和DeflaterlnputStream


    正确答案:B

  • 第2题:

    下面Java语句从指定的网址读取HTML文件,在下画线处应填上的选项是 Reader in=new______(new URL(urlString).openStrream());

    A.Reader

    B.DataOutputStream

    C.ByteArrayInputStream

    D.InputStreamReader


    正确答案:A

  • 第3题:

    在下列程序的空白处,应填入的正确选项是( )。 Importjava.io.*; PulilcclassObjectStreamTest{ Publilcstaticvoidmain(string args [])thowsIOException{ ObjectOutputStream os=new ObjectOutputStream (newFileOutputStream(“serial.bln”)); Java.util.Dated=newJava.util.Date(); Oos______(d); ObjectlnputStreamois= newObjectlnputStream(newFileOutputStream(“serial.bin”)); try{ iava.util.daterestoredDate= (Java.util.Date)ois.readObject(); System.out.println (“readobjectbackfromserial.binfile:” +restoredDate); } Catch(ClassNotFoundException cnf){ System.out.println(“classnotfound”); } }

    A.WriterObject

    B.Writer

    C.BufferedWriter

    D.writerObject


    正确答案:D
    解析:本题考查的是输入输出及文件操作,WriterObject方法是往数据流中写入数据。

  • 第4题:

    阅读下列Java语句: ObjectOutputStream Ut=new ObjectOutputStream(new ("employee.dat&quo

    阅读下列Java语句:

    ObjectOutputStream Ut=new ObjectOutputStream

    (new ("employee.dat"));

    在下画线处,应填的正确选项是( )。

    A.File

    B.FileWriter

    C.FileOutputStream

    D.Outputstream


    正确答案:C
    C。【解析】ObjectOutputStream即继承了0utputStream抽象类,又实现了ObjectOutput接口,这是Java用接口技术代替双重继承的例子,其构造方法参数是串行化了的对象。所以,此处应为串行化的文件输出流。

  • 第5题:

    下列代码将对象写入的设备是( )。 ByteArrayOutputStream bout=new ByteArrayOut- putStream; ObjectOutputStream ut=new ObjectOutputStream (bout); out.writeObject(this); out.close;

    A.内存

    B.硬盘

    C.屏幕

    D.网络


    正确答案:A
    A。【解析】ObjectOutputStream类的构造方法是obiectoutputStream(OutputStreamout)。Java中的二进制流全都写入到内存中。

  • 第6题:

    下列程序将Date对象写入文件file42.txt中,选择正确的语句填入下列程序中的横线处。 package ch1; impbrt java. io. *; import java. util. *; public class ex42 { static String fileName = "ch1\\file42.txt"; static Date date = null; public static void main(String[] args) { date = new Date(); try { FileOutputStream fos = new FileOutputStream(file Name); ObjectOutStream os = new ObjectOutputStream(fos); oos.______; oos.close(); fos.close(); System.out.println(date.toString()); } catch(Exception e) { System.out.println(e.getMessage()); } } }

    A.writeObject()

    B.writeObject(date)

    C.write(date)

    D.writeByte(date)


    正确答案:B

  • 第7题:

    ( 34 )在下列程序的空白处,应填入的正确选项是

    Import java.io.*;

    Pulilc class ObjectStreamTest{

    Publilc static void main(string args[]) throws IOException{

    ObjectOutputStream s= new ObjectOutputStream

    (new FileOutputStream( “ serial.bin ” ));

    Java .util.Date d= new Java.util.Date();

    Oos___________ (d);

    ObjectInputStream is=

    new ObjectInputStream(new FileOutputStream( “ 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 ” );

    }

    A ) WriterObject

    B ) Writer

    C )BufferedWriter

    D ) WriterObject


    正确答案:D

  • 第8题:

    import java.io.*;  public class Forest implements Serializable {  private Tree tree = new Tree();  public static void main(String [] args) {  Forest f= new Forest();  try {  FileOutputStream fs = new FileOutputStream(”Forest.ser”);  ObjectOutputStream os = new ObjectOutputStream(fs);  os.writeObject(f); os.close();  } catch (Exception ex) { ex.printStackTrace(); }  }  }  class Tree { }  What is the result?() 

    • A、 Compilation fails.
    • B、 An exception is thrown at runtime.
    • C、 An instance of Forest is serialized.
    • D、 A instance of Forest and an instance of Tree are both serialized.

    正确答案:B

  • 第9题:

    单选题
    在下列程序的空白处,应填入的正确选项是(  )。import java.io.*; public class ObjectStreamTest{ public static void main(string args[])throws IOException{ ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("serial.bin")); Java.until.Date d=new Java.until.Date(); oos.______(); ObjectInputStream ois=new ObjectlnputStream(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"); } }
    A

    readObject

    B

    Writer

    C

    BufferedWriter

    D

    writeObject


    正确答案: C
    解析:
    java.io包中,提供了0bjectInputStream和ObjectOutputStream将数据流功能扩展至可读写对象。在ObjectInputStream中用readObject()方法可以直接读取一个对象,0bjectOutputStream中用writeObject()方法可以直接将对象保存到输出流中。B项和C项,Writer和BufferedWriter都为java.io包中的类。

  • 第10题:

    单选题
    What writes the text “ ” to the end of the file “file.txt”?()
    A

     OutputStream out= new FileOutputStream (“file.txt”);       Out.writeBytes (“ /n”);

    B

     OutputStream os= new FileOutputStream (“file.txt”, true);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);

    C

     OutputStream os= new FileOutputStream (“file.txt”);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);

    D

     OutputStream os= new OutputStream (“file.txt”, true);     DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);


    正确答案: C
    解析: 暂无解析

  • 第11题:

    单选题
    阅读下列代码段:ByteArrayOutputStream bout=new ByteArrayOutputStream();ObjectOutputStream out=new ObjectOutputStream(bout);out.writeObject(this);out.close();以上代码段的作用是(  )。
    A

    将对象写入内存

    B

    将对象写入硬盘

    C

    将对象写入光盘

    D

    将对象写入文件


    正确答案: A
    解析:
    在java.io包中,提供了ByteArrayInputStream、ByteArrayOutputStream和StringBufferInputStream类可直接访问内存,它们是InputStream和OutputStream的子类。用ByteArrayOutputStream可以向字节数组(缓冲区)写入数据。在ObjectInputStream中用readObject()方法可以直接读取一个对象,ObjectOutputStream中用writeObject()方法可以直接将对象保存到输出流中。

  • 第12题:

    单选题
    下列Java语句从指定网址读取html文件,在下画线处应填上的选项是(  )。Reader in=new ______(new URL(urlString).openStream());
    A

    Reader

    B

    DataOutputStream

    C

    ByteArrayInputStream

    D

    InputStreamReader


    正确答案: A
    解析:
    由“Reader in=…”可以判断填入的类一定是Reader类,而参数里面的是字节流,因此为InputStreamReader,Reader为抽象类,不能直接创建对象。

  • 第13题:

    阅读下面Java语句 ObjectOutputStream ut=new ObjectOutputStream(new______("employee.dat"));在下画线处,应填的正确选项是

    A.File

    B.FileWriter

    C.FileOutputStream

    D.OutputStream


    正确答案:C
    解析:类ObjeetOutputStream是将一个对象写到一个流中,其原型为public ObjectOutputStream(OutputStream out),即参数为一个输出流。显然,在空白处新建了一个输出流的对象,其后还有一个参数“employee.dat”,是一个文件名,本题目的意思为将对象写入一个文件输出流。public FileOutputStream(String name),创建一个向具有指定名称的文件中写入数据的输出文件流。答案为C。

  • 第14题:

    选择正确的语句填在下列程序的横线处,使程序正常运行。 package ch1; import java. io. *; import j ava. util. *; class C45 implements Seritizable ______Public Thread t = new Thread(new T45(), "t"); public intcnt = 0; public C45() { t. start ( ) class T45 implements Runnable public int[] a = new int[4]; public void run() { for(int i - 0; i < 4; i++) { a[i] - i +4; } } } public class ex45 { static String fileName = "ch1\\file45.txt"; public static void main(String[] args) throws Exception { C45 bj = new C45 (); FileOutputStream fos = new FileOutputStream(fileName); ObjectOutputStream os = new ObjectOutputStream(fos); oos. writeObject (obj); oos.clese (); fos.close (); System. out, println (obj . toString ( ) ); } }

    A.transient

    B.protected

    C.package

    D.final


    正确答案:A

  • 第15题:

    阅读下列Java语句:在下画线处,应填的正确选项是( )。

    A.File

    B.FileWriter

    C.FileOutputStream

    D.Outputstream


    正确答案:C
    ObjectOutputStream即继承了0utput-Stream抽象类,又实现了0bjectOutput接口,这是Java用接口技术代替双重继承的例子,其构造方法参数是串行化了的对象。所以,此处应为串行化的文件输出流。

  • 第16题:

    阅读下列代码片段在下画线处,应填的正确选项是( )。

    A.Implementation

    B.Inheritance

    C.implements

    D.extends


    正确答案:D
    继承父类应使用的关键词为extends。

  • 第17题:

    阅读下列Java语句: ObjectOutputStream Ut=new ObjectOutputStream(new ("employee.dat")); 在下画线处,应填的正确选项是( )。

    A.File

    B.FileWriter

    C.FileOutputStream

    D.Outputstream


    正确答案:C
    C。【解析】ObjectOutputStream即继承了0utputStream抽象类,又实现了ObjectOutput接口,这是Java用接口技术代替双重继承的例子,其构造方法参数是串行化了的对象。所以,此处应为串行化的文件输出流。

  • 第18题:

    阅读厂列Java语句 ObjectOutputStreamout=new ObjectOu中utStream(new______("employee.daf")); 在下划线处,应填的正确选项是( )。

    A.File

    B.FileWriter

    C.FileOutputStream

    D.Outputstream


    正确答案:C
    解析:ObjectOutputStxeam即继承了OutputStream抽象类,又实现了ObjectOutput接口,这是Java用接口技术代替双重继承的例子,其构造方法参数是串行化了的对象。所以,此处应为串行化的文件输出流。

  • 第19题:

    创建一个向文件“file.txt”追加内容的输出流对象的语句有()。

    • A、FileOutputStream out=new FileOutputStream(“file.txt”,true);
    • B、OutputStream out=new FileOutputStream(“file.txt”,“append”);
    • C、OutputStream out=new FileOutputStream(“file.txt”);
    • D、FileOutputStream out=new FileOutputStream(new file(“file.txt”));
    • E、OutputStream out=new FileOutputStream(new File(“file.txt”),true.;

    正确答案:A,E

  • 第20题:

    What writes the text “ ” to the end of the file “file.txt”?()

    • A、 OutputStream out= new FileOutputStream (“file.txt”);       Out.writeBytes (“ /n”);
    • B、 OutputStream os= new FileOutputStream (“file.txt”, true);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);
    • C、 OutputStream os= new FileOutputStream (“file.txt”);       DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);
    • D、 OutputStream os= new OutputStream (“file.txt”, true);     DataOutputStream out = new DataOutputStream(os);  out.writeBytes (“ /n”);

    正确答案:B

  • 第21题:

    单选题
    import java.io.*;  public class Forest implements Serializable {  private Tree tree = new Tree();  public static void main(String [] args) {  Forest f= new Forest();  try {  FileOutputStream fs = new FileOutputStream(”Forest.ser”);  ObjectOutputStream os = new ObjectOutputStream(fs);  os.writeObject(f); os.close();  } catch (Exception ex) { ex.printStackTrace(); }  }  }  class Tree { }  What is the result?()
    A

     Compilation fails.

    B

     An exception is thrown at runtime.

    C

     An instance of Forest is serialized.

    D

     A instance of Forest and an instance of Tree are both serialized.


    正确答案: B
    解析: 暂无解析

  • 第22题:

    单选题
    下列代码将对象写入的设备是(  )。ByteArrayOutputStream bout = new ByteArrayOutputStream();ObjectOutputStream out = new ObjectOutputStream(bout);Out.writeObject(this);Out.close();
    A

    内存

    B

    硬盘

    C

    屏幕

    D

    网络


    正确答案: B
    解析:
    Java中的二进制流全都写入到内存中。ByteArrayOutputStream是读写内存流类,用于向字节数组中写入数据。ObjectOutputStream.writeObject()的作用是把一个实例的对象写入对象输出流中。

  • 第23题:

    单选题
    为使下列代码正常运行,应该在下画线处填人的选项是(  )。ObjectInputStream in = new ____(new FileInputStream(employee.dat));Employee[] newStaff = (Employee[]) in.readObject();in.close();
    A

    Reader

    B

    InputStream

    C

    ObjectInput

    D

    ObjectInputStream


    正确答案: B
    解析:
    ObjectInputStream类和0bjectOutputStream类分别是InputStream类和0utputStream类的子类。ObjectInputStream类和0bjectOutputStream类创建的对象被称为对象输入流和对象输出流。对象输入流可以使用readObject()方法读取一个对象到程序中。