内存
硬盘
屏幕
网络
第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());
}
}
}
第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
第3题:
下列代码将对象写入的设备是( )。
A.内存
B.硬盘
C.屏幕
D.网络
第4题:
阅读下列Java语句:
ObjectOutputStream Ut=new ObjectOutputStream
(new ("employee.dat"));
在下画线处,应填的正确选项是( )。
A.File
B.FileWriter
C.FileOutputStream
D.Outputstream
第5题:
阅读下列Java语句: ObjectOutputStream Ut=new ObjectOutputStream(new ("employee.dat")); 在下画线处,应填的正确选项是( )。
A.File
B.FileWriter
C.FileOutputStream
D.Outputstream
第6题:
第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
第8题:
在J2EE中,用JAXP转化XML文档,可以创建输出流把数据输出到屏幕上,以下创建该输出流的代码是()
第9题:
Stream result = stream.newStream(System.out)
StreamResult result = new StreamResult(System.out)
Stream result = new Stream(System.out)
StreamResult result = DOMSource.newStreamResult(System.out)
第10题:
out.newLine()
out.clear()
out.flush()
out.clearBuffer()
第11题:
File
FileWriter
FileOutputStream
OutputStream
第12题:
Stream result = stream.newStream(System.out);
StreamResult result = new StreamResult(System.out);
Stream result = new Stream(System.out);
StreamResult result = DOMSource.newStreamResult(System.out);
第13题:
阅读下面Java语句 ObjectOutputStream ut=new ObjectOutputStream(new______("employee.dat"));在下画线处,应填的正确选项是
A.File
B.FileWriter
C.FileOutputStream
D.OutputStream
第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
第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
第16题:
下列代码将对象写入的设备是( )。 ByteArrayOutputStream bout=new ByteArrayOut- putStream; ObjectOutputStream ut=new ObjectOutputStream (bout); out.writeObject(this); out.close;
A.内存
B.硬盘
C.屏幕
D.网络
第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)
第18题:
A.ByteArrayOutputStream流中缓冲区的大小不能被定义
B.ByteArrayOutputStream流关闭后仍可被调用,并且不会产生任何IOException
C.ByteArrayOutputStream流关闭后不能被使用,否则抛出IOException
D.ByteArrayOutputStream流必须与ByteArrayInputStream流配对使用
第19题:
下列哪个类的方法能够直接把简单数据类型写入文件?()
第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?()
第21题:
readObject
Writer
BufferedWriter
writeObject
第22题:
Compilation fails.
An exception is thrown at runtime.
An instance of Forest is serialized.
A instance of Forest and an instance of Tree are both serialized.
第23题:
将对象写入内存
将对象写入硬盘
将对象写入光盘
将对象写入文件