单选题在下列程序的空白处,应填入的正确选项是( )。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"); }}AreadObjectBWriterCBufferedWriterDwriteObject
单选题
在下列程序的空白处,应填入的正确选项是( )。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
参考解析
解析:
java.io包中,提供了0bjectInputStream和ObjectOutputStream将数据流功能扩展至可读写对象。在ObjectInputStream中用readObject()方法可以直接读取一个对象,0bjectOutputStream中用writeObject()方法可以直接将对象保存到输出流中。B项和C项,Writer和BufferedWriter都为java.io包中的类。
java.io包中,提供了0bjectInputStream和ObjectOutputStream将数据流功能扩展至可读写对象。在ObjectInputStream中用readObject()方法可以直接读取一个对象,0bjectOutputStream中用writeObject()方法可以直接将对象保存到输出流中。B项和C项,Writer和BufferedWriter都为java.io包中的类。
相关考题:
2下列程序实现对ZIP 文件file.zip 的检索,在横线处填入正确的语句是( )。package test;import java.io.*;import java.util.*; import java.util.zip.*;public class Exam{ public static void main(String[] args){ try{ FileInputStream fis = new FilelnputStream("test/file.zip"); ZipInputStream zis = new ZiplnputStream(fis); ZipEntry en; while ((______ )!= null){ en.getName(); zis.closeEntry(); } zis.close(); } catch(Exception e){ e.pfintStackTrace(); }}A.en = zis. getNextEntry()B.en == zis.getNextEntry(C.en=zis. getEntry()D.zis.getNextEntry()
下列Java源程序结构中前三种语句的次序,正确的是A.import, package, public classB.import必为首,其他不限C.public class, import, packageD.package, import, public class
在下面Java Applet程序的下画线处填入代码,使程序完整并能够正确运行。import java.applet.*;import java.awt.*;public class HelloWorld ______ {public void paint(Graphics g) {g.drawString("Hello World!",25,25);}}
下面程序运行时输出的结果为C:\Program Files is a directory.将程序补充完整。Import java.io.*;public class DirTest {public static void main(String[] args) {File myDir=Flew File("C:/Program Files/");System.out.println(myDir+(______.isDirectory()?"is":"is not")+"a directory.");}}
阅读下面程序import java.io.*;public class ByteStream Test{public static void main(String[] a){int[] myArray = {10,20.30,40};try{DataOutputStream dos = new DataOutputStream(new _________________( " ints.dat " ));for (int i=0;imyArray.length;i++)dos.writeInt(myArray[i] ) ;dos.close();S ystem.out.println( " Have written binary file ints.dat " );}catch (IOException ioc){System.out.println( " IO Exception " );}}}为保证程序正确运行,在程序中下划线处应填入的代码是A)FileOutputStreamB)ByteArrayOutputStreamC)BufferedOutputStreamD)FileWriter
(11 )下面程序运行时输出结果为C:\Program Files is a directory请将程序补充完整。import Java.io.*;public class DirTest{public static void main(String[] args){File myDir = new File( " C:/Program Files/ " );System.out.println(myDir + ( 【 11 】 .isDirectory() ? " is " : " is not " ) + " a directory. " );}}
下列程序构造了一个 Swing Applet ,请在下划线处填入正确的代码Import javax.swing.*;Import java.awt.*;Public class SwingApplet extends 【 13 】 {Jlabel l = new Jlabel ( “ This is a Swing Applet. ” );Public void init(){Container contentPane = getContentPane();contentPane.add(1);}}
( 20 )在下列程序的空白处,应填入的正确选项是import java.io.*;Public class writeInt{Public static void main(string[ ] a) {Int[ ] myArray = {10,20,30,40};try{DataOutputSystem dos= new DataOutputSystem( new FileOutputSystem( “ ints.dat ” ) ) ;for ( int i=0 ; ImyArray.length ; i++ )dos 。 writeInt ( myArray[i] ) ;dos.System.out.println( “ Have written binary file ints.dat ” );}Catch(IOException ioe){ System.out.println( “ IO Exception ” );}}}A)start( )B)close( )C)read( )D)write( )
下列哪个选项的java源文件代码片段是不正确的?A.package testpackage; public class Test{ }B.import java. io. *; package testpaekage; public class Test { }C.import java.io.*; class Person { } public class Test { }D.import java.io.*; import java. awt.*; public class Test{ }
下列程序实现对ZIP文件file.zip的检索,在横线处填入正确的语句 package test; import java.io.*; import java.util.*; import java.util.zip.*; public class Exam { public static void main(String[] args){ try{ FileInputStream fis=new FileInputStream("test/file.zip"); ZipInputStream zis=new ZipInputStream(fis); ZipEntry en; while((______)!=null){ en.getName(); zis.closeEntry(); } zis.close(); } catch(Exception e){ e.printStackTrace(); } } }A.en=zis.getNextEntry()B.en==zis.getNextEntry()C.en=zis.getEntry()D.zis.getNextEntry()
下列( )选项的java源文件代码片段是不正确的。A.package testpackage; publicClass Test{}B.import java.io.*; package testpackage: publicClass Test{}C.import java.io.*; Class Person{} publicClass Test{}D.import java.io.*; import java.awt.*; publicClass Test{}
下列程序将类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 RunnableB.implements SedalizableC.extends SerializableD.implements InputStream
阅读下面Applet程序 import javax. swing. *; import java. awt. *; public class SwintgApplet extends JApplet{ JLabel 1=new JLabel("This is a Swing Applet."); public void init(){ ________________________________ } } 在程序下画线处填入正确的选项是A.Container contentPane=getContenPane(); cotentPane. add(1);B.JPanel comtenPane=new Jpane(); contentPane. add(1);C.contentPane. add(1);D.add(1);
下列代码的输出结果是( )。class parent{void printme(){System.out.println("parent");}}class child extends parent{void printme(){System. out.println("child");}void printall(){super, printme();this.printme();printme();}}public class test{public static void main(String args[]){child myc=new child();myc.printall();}}A.import java.awt.*;B.import java.applet.applet;C.import java.io.*;D.import java, awt.graphics;
下列哪个选项的java源文件程序段是不正确的? ( )A.package testpackage; public class Test{ }B.import java.io.*; package testpackage; public class Test{ }C.import java.i.*; class Person{} public class Test{ }D.import java.io.*; import java.awt.*; public class Test { }
下面程序构造了一个Swing Applet,在下画线处填入正确的代码。import javax.swing.*;import java.awt.*;public class SwingApplet extends ______ {JLabel 1=new JLabel("This is a Swing Applet.");public void init() {Container contentPane=getContentPane();contentPane.add(1);}}
下列代码的下画线处应填入的方法名是( )。 import java.awt.*; import java.applet.*; public class Hello extends Applet{ public void (Graphics g){ 9.drawstring("How are you!",l0,10); } }A.repaintB.printlnC.paintD.show
阅读下面写文件的程序 import java.io.*: public class WriteFile{ public static void main(String[] A) { int[] myArray={10,20,30,40}; try { FileOutputStream f=new FileOutputStream("ints.dat"); DataOutputStream ______ =new DataOutputStream(f); for(int i=0;i<myArray.length;i++)dos.writeInt(myArray[i]); dos.close(); System.out.println("Have written binary file ints.dat"); } catch(IOException ioe) { System.out.println("IOException"); } } } 程序中下画线处应填入的正确选项是A.myArrayB.dosC.ioeD.ints
阅读下面Applet程序 import javax.swing.*: import java.awt.*: public Class Test SwingApplet extends JApplet { JLabel 1=new JLabel("This is a Swing Applet."); public void init() { ______ } } 程序中下画线处应填入的正确选项是A.Container contentPane=getContentPane();contentPane.add(1);B.Jpanel contentPane=new JPanel();contentPane.add(1);C.contentPane.add(1);D.add(1);
要使下列程序能够正确运行,则横线处应填写的内容是( )。 import Java.awt.*; import java.applet.*; public class SayHi extends Applet{ public void (Graphics g){ 9.drawString("Hi!",20,20); } }A.intB.startC.paintD.stop
在下列程序的空白处,应填入的正确选项是( )。 Import java.io.*; Pulilc class ObjectStreamTest{ Publilc static void main(string args[])throws IOEx- ception{ OhiectOutputStream os=new OhjectOutputStream (new FileOutputStream("serial.bin")); Java.util.Date d=new Java.util.Date; Oos (d); ObjectInputStream is= new OhjectlnputStream(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.WriterObjectB.WriterC.BufferedWriterD.writerObject
下列程序实现对ZIP文件file.zip的检索,在横线处填入正确的语句 package test; import java.io.*: import java.util.*; import java.util.zip.*; public class Exam { public static void main(String[])args){ try{ FileInputStream fis=new FileInputStream("test/file.zip"); ZipInputStreamzis=new ZipInputStream(fis); ZipEntry en; while ((_____)!=null){ en.getName(); zis.closeEntry(); } zis.close(); } catch(Exception e) { e.printStackTrace(); } } }A.en = zis.getNextEntry()B.en = zis.getNextEntry()C.en = zis.getEntry()D.zis.getNextEntry()
请在下划线处填入代码,使程序能够正确运行。import java .awt.*;import java .applet.*;public class SayHi extends Applet{public void【 】(Graphics g){g .drawString(“Hi!”20,20);}}
( 8 )在下列 Java applet 程序的横线处填入代码,使程序完整并能够正确运行。Import java. awt. *;Import java. applet. *;Public class Greeting extends applet{Public void 【 8 】 (Graphics g) {g.drawSting( “ how are you! ” ,10,10);}}
( 20 ) 下列程序的功能是将一个整数数组写入二进制文件 。 在程序的下划线处应填入的选项是import java.io.*;public class XieShuzu{public static void main(String[] a){int [] myArray={10,20,30,40};try{DataOutputStream dos=new DataOutputStream(new FileOutputStream( " ints.dat " ));for(int i=0;imyArray.lenth;i++)dos. _______(myArray[i]);dos.close();System.out.println( " 已 经 将 整 数 数 组 写 入 二 进 制 文 件 :ints.dat " );}catch(IOException ioe){System.out.println( " IO Exception " );}}}A ) writeArrayB ) writeByteC ) writeIntD ) writeDouble
单选题下列Java源程序结构中前三种语句的次序,正确的是( )。Aimport,package,public classBimport必为首,其他不限Cpublic class,package,importDpackage,import,public class