单选题下列代码将对象写入的设备是(  )。ByteArrayOutputStream bout = new ByteArrayOutputStream();ObjectOutputStream out = new ObjectOutputStream(bout);Out.writeObject(this);Out.close();A 内存B 硬盘C 屏幕D 网络

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

内存

B

硬盘

C

屏幕

D

网络


相似考题
更多“单选题下列代码将对象写入的设备是(  )。ByteArrayOutputStream bout = new ByteArrayOutputStream();ObjectOutputStream out = new ObjectOutputStream(bout);Out.writeObject(this);Out.close();A 内存B 硬盘C 屏幕D 网络”相关问题
  • 第1题:

    请完成程序,首先由一个类simple实现Serializable接口,并有三个成员变量,分别为int型、double型和String型,可以用toString的方法显示这三个成员变量。在main方法中创建这个simple的持久对象,根据用户在命令行输入的三个参数来设定其中成员变量的值。然后,将这个对象写入名为TheSerial.data的文件中,并显示成员变量。最后从文件TheSerial.data中读出三个成员变量并显示出来。

    注意:请勿修改main()主方法和其他已有语句内容,仅在横线处填入适当语句。

    import java.io.*;

    class TheSerial implements Serializable

    {

    private int intvalue;

    private double doublevalue;

    private String string;

    The Serial ()

    {

    intvalue=123;

    doublevalue=12.34;

    string="Serialize Test";

    }

    public void setDouble(double d)

    {

    doublevalue=d;

    }

    public void setInt(int i)

    {

    intvalue=i;

    }

    public void setString(String s)

    {

    string=s;

    }

    public String to String()

    {

    return("int="+intvalue+" double="+doublevalue+" string="+string);

    }

    }

    public class simple

    {

    public static void main(String[] args)

    {

    The Serial e1=new TheSerial();

    TheSerial e2;

    try

    {

    e1.setInt(Integer.parseInt(args[0]));

    e1.setDouble(Double.parseDouble(args[1]));

    e1.setString(args[2]);

    }

    catch(Exception e)

    {

    e1.setString(e.getMessage());

    }

    System.out.println(e1);

    try

    {

    FileOutputStream S=new FileOutputStream("TheSerial.data");

    ObjectOutputStream OS=new ObjectOutputStream(oS);

    ______;

    }

    catch(IOException ioException)

    {

    System.out.println (ioException.getMessage ());

    }

    try

    {

    FileInputStream iS=new FileInputStream("TheSerial.data");

    ObjectInputStream IS=new ObjectInputStream(iS);

    ______;

    System.out.println(e2);

    }

    catch(IOException ioException)

    {

    System.out.println(ioException.getMessage());

    }

    catch(ClassNotFoundException cnfException)

    {

    System.out.println(cnfException.getMessage());

    }

    }

    }


    正确答案:oOs.writeObject(e1) e2=(TheSerial)oIS.readObject()
    oOs.writeObject(e1) e2=(TheSerial)oIS.readObject() 解析:本题考查知识点:串行化要领和目的、串行化方法、基于文本的应用。解题思路:本题主要考查串行化相关的方法和实现。解题中首先要掌握串行化的基本过程和反串行化的过程。串行化过程首先要创建一个FileOutputStream,通过该类的实例对文件进行访问,然后创建一个ObjectOutputStream对象,通过writeObject()方法来实现对象的序列化。第1个空就是使用writeObject()实现序列化。反序列化过程中用FileInputStream对象建立读取文件的连接,并使用该对象创建一个ObjectInputSream实例的readObject()方法就可以实现对象的反序列化。第2个空就是使用readObject()实现反序列化。

  • 第2题:

    下列程序将类C15的对象写入文件filetxt,选择正确的语句填入下列程序的横线处。 package ch2; import java.util.*; import java.io.*; class C15______ { public iht a; public void setInt(int newa) { a = newa; } } public class Testl5 { pulibc static void main(String[] args) { C15 bj = new C15(); try { FileOutputStream fos =newFileOutputStream("ch2\\filel5.txt"); ObjectOutputStream os = ObjectOutputStream(fos); Obj.setInt(10); oos.writeObject(obj); oos.close (); fos.close(); } catch(IOException ioe) { ioe.printStackTrace(); } } }

    A.implements Runnable

    B.implements Sedalizable

    C.extends Serializable

    D.implements InputStream


    正确答案:B
    解析:类C15必须实现Serializable接口,否则无法进行对象流的写入。

  • 第3题:

    下列代码将对象写入的设备是( )。

    A.内存

    B.硬盘

    C.屏幕

    D.网络


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

  • 第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题:

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

    A.File

    B.FileWriter

    C.FileOutputStream

    D.Outputstream


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

  • 第6题:

    ByteArrayOutputStream类会在创建对象时就创建一个()型数组的缓冲区


    答案:byte

  • 第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题:

    在J2EE中,用JAXP转化XML文档,可以创建输出流把数据输出到屏幕上,以下创建该输出流的代码是() 

    • A、 Stream result = stream.newStream(System.out)
    • B、 StreamResult result = new  StreamResult(System.out)
    • C、 Stream result = new Stream(System.out)
    • D、 StreamResult result = DOMSource.newStreamResult(System.out)

    正确答案:B

  • 第9题:

    单选题
    在J2EE中,用JAXP转化XML文档,可以创建输出流把数据输出到屏幕上,以下创建该输出流的代码是()
    A

     Stream result = stream.newStream(System.out)

    B

     StreamResult result = new  StreamResult(System.out)

    C

     Stream result = new Stream(System.out)

    D

     StreamResult result = DOMSource.newStreamResult(System.out)


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

  • 第10题:

    单选题
    能清除缓冲区中的数据,并且把数据写到客户端是out对象中的方法是()。
    A

    out.newLine()

    B

    out.clear()

    C

    out.flush()

    D

    out.clearBuffer()


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

  • 第11题:

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

    File

    B

    FileWriter

    C

    FileOutputStream

    D

    OutputStream


    正确答案: D
    解析:
    将对象转换为字节流保存起来,并在日后还原这个对象,这种机制称做对象串行化。ObjectOutputStream类的构造方法参数是串行化了的对象。此处是串行化了的文件输出流FileOutputStream,本题也可以填写ByteArrayOutputStream,这两种是Java中很经典的串行化模式。

  • 第12题:

    单选题
    在J2EE中,用JAXP转化XML文档,可以创建输出流把数据输出到屏幕上,以下创建该输出流的代码是()。
    A

    Stream result = stream.newStream(System.out);

    B

    StreamResult result = new StreamResult(System.out);

    C

    Stream result = new Stream(System.out);

    D

    StreamResult result = DOMSource.newStreamResult(System.out);


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

  • 第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题:

    在下列程序的空白处,应填入的正确选项是( )。 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方法是往数据流中写入数据。

  • 第16题:

    下列代码将对象写入的设备是( )。 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中的二进制流全都写入到内存中。

  • 第17题:

    下列程序将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

  • 第18题:

    下列选项中,关于ByteArrayOutputStream类的描述正确的是?()

    A.ByteArrayOutputStream流中缓冲区的大小不能被定义

    B.ByteArrayOutputStream流关闭后仍可被调用,并且不会产生任何IOException

    C.ByteArrayOutputStream流关闭后不能被使用,否则抛出IOException

    D.ByteArrayOutputStream流必须与ByteArrayInputStream流配对使用


    答案:B
    解析:使用ByteArrayOutputStream(int size)构造方法便可以设置缓冲区的大小;ByteArrayOutputStream流关闭后仍可被调用,并且不会产生任何IOException。ByteArrayOutputStream流与ByteArrayInputStream流分别对应的是字节输出流和字节输入流,没有强制要求配对使用。

  • 第19题:

    下列哪个类的方法能够直接把简单数据类型写入文件?()

    • A、OutputStream
    • B、BufferedWriter
    • C、ObjectOutputStream.
    • D、FileWriter

    正确答案:C

  • 第20题:

    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

  • 第21题:

    单选题
    在下列程序的空白处,应填入的正确选项是(  )。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包中的类。

  • 第22题:

    单选题
    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
    解析: 暂无解析

  • 第23题:

    单选题
    阅读下列代码段: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()方法可以直接将对象保存到输出流中。