就业数据资源平台
当前位置:首页 > Java语言程序设计
2011年计算机等级考试二级Java笔试练习题(6)

1.ObjectInputStream 的父类是 。

  A.)InputStream B)OutputStream C)Reader D)Writer


  2.在java中,用来处理字符的基本存储单位的 。


  A)单字节 B)双字节 C)3字节 D)4字节


  3.ZipInputStream所在的包是 .


  A).java.io B)java.util C)java.io.zip D)java.util.zip


  4.readFloat()所在类是 。


  A) DataInput B)InputStreamReader C)DataInputStream D)BufferedInputStream


  5.同时支持readInt()和write()方法的类是______________.


  A)RandomAccessFile B)File C)Read D)Write


  6.读一个压缩文件,该压缩文件对象参数的类是____________.


  A)File B)FileInputStream C)ZipInputStream D)BufferedReader


  7.JarInputStream所属流是_________________.


  A)FileInputStream B)BufferedInputStream C)ZipInputStream D)DataInputStream


  8.如果想保留对象数据,首先需要打开的对象是____________.


  A)ObjectOutputStream B)FileOutputStream C)BufferedOutputStream D)ZipOutputStream


  9.下列File类操作中错误的是___________.


  A)文件的建立 B)文件的删除 C)文件的读写 D)文件的属性


  10.在计算CRC校验和的程序中使用java.nio的新特性后,速度提高约23倍,所用技术是_______________.


  A) 校验和 B)文件琐 C)字符编码解码 D)内存映射


  11.BufferedReader阅读文本行的方法是______________.


  12.以下是一个对数据文件进行缓冲输入操作的句子,在语句的下划线处,请填上适当的内容:


  DataInlputStream din= new DataInputStream(new _____(new FileInputStream(“employee.dat”)));


  13.正如Java的流类中也有不属于java.io包的,比如:“摘要”输入流类DigestInputStream属于java.security包,同样,ZipInputStream属于_______接口。


  14.代表一个随机访问文件的类是______类。


  15.如果对象需要进行输入,着该对象必须实现________接口。


  16.阅读一个网页中的html文件,寻找和相匹配的字符串。这就要将java.io.InputStreamReader和java.util.regex包的_____________类和Matcher类相结合。


  17.请编写一个完整的java程序,将一个文件(例如empllyee.dat)的属性置为只读模式。


  18.请编写一个完整的java程序,向一个文件(例如empllyee.dat)写入10个字符串。


  19.请编写一个完整的java程序,将source.txt中的“这是在源文件中的数据”读出来显示在屏幕上,并且写入到destination.txt文件中。


  20.请试在以下程序的“…”处填上适当的语句。(选作)有时可将一个对象写在ByteArrayOutputStream流中,再从该流中读入同样一个对象到ByteArrayOutputStream中,这样也可以深层次克隆一个对象。


  Import java.io.*;


  Public class SerialCloneTest1


  {


  Public static void main(String args[])


  {


  Student harry=new Student(“Harry Hacker”,”Computer”);


  Student harry2=(Student)harry.clone();


  System.out.println(harry);


  System.out.println(harry2)


  }


  }


  Class SerialCloneable implements Cloneable,Serializable


  {


  Public Object clone()


  {


  Try{


  …//请填上适当的语句,完成Student对象harry的克隆。


  }


  Catch(Exception e)


  {


  Return null;


  }


  }


  }


  Class Student extends SerialCloneable


  {


  Public Student(String n,String m)


  {


  Name=n;


  Major=m;


  }


  Public String toString()


  {


  Return getClass().getName()+”[name=”+name+”,major=”+major+”]


  }


  Private String name;


  Private String major;


  }


答案

  1.A 2B 3D 4C 5A 6B 7C 8A 9C 10D


  11.readerLine() 12.BufferedInputStream() 13.java.util.zip 14.RandomAccessFile 15.Serializable 16.Pattern


  17.代码如下:


  Import java.io.*;


  Class SetReadOnlyText


  {


  Public static void main(String [] args)


  {


  If(args.length !=1)


  {


  System.err.println(“usage:java Main”);


  System.exit(-1);


  }


  If((new File(args[0])).setReadOnly())


  {


  System.out.println(“set File to ReadONly mode”);


  }


  Else


  {


  System.out.println(“Cannot set to read-only mode”);


  }


  }


  }


  18.代码如下:


  Import java.io.*;


  Public class WriteChar


  {


  Public static void main(String args[])


  {


  Int I;


  Byte[] b=new byte[10];


  Try


  {


  DataOutputStream out=new DataOutputString(new FileOutputStream(“employee.dat”));


  For(i=0;i<10;i++)


  {


  B[i]=(byte)(48+i);


  }


  Out.write(b);


  Out.close();


  }


  Catch(Exception e)


  {


  }


  }


  }


  19.代码如下:


  Import java.io.*;


  Public class ReadWriteChar


  {


  Public static void main(String args[])


  {


  String s=new String();


  Try


  {


  BufferedReader in =new BufferedReader(new FileReader(“source.txt”));


  PrintWriter out=new Print Writer(new FileWriter(“destination.txt”));


  Out.println(“The following is from source”);


  While((s=in.readLine())!=null)


  {


  System.out.println(s);


  Out.println(s)


  }


  In.close();


  Out.close();


  }


  Catch(Exception e)


  {}


  }


  }


20.代码如下:

  Import java.io.*;


  Public class SerialCloneTest1


  {


  Public static void main(String args[])


  {


  Student harry=new Student (“Harry Hacker”,”Computer”);


  Student harry2=(Student)harry.clone();


  System.out.println(harry);


  System.out.println(harry2);


  }


  }


  Class SerialCloneable implements Cloneable,Serializable


  {


  Public Object clone()


  {


  Try


  {


  ByteArrayOutputStream bout = new ByteArrayOutStream();


  ObjectOutputStream out=new ObjectOutputStream(bout);


  Out.writeObject(this);


  Out.close();


  ByteArrayInputStream bin=new ByteArrayInputStream(bout.toByteArray());


  ObjectInputStream in = new ObjectInputStream(bin);


  Object ret=in.readObject();


  In.close();


  Return ret;


  }


  Catch(Exception e)


  {


  Return null;


  }


  }


  }


  Class Student extent SerialCloneable


  {


  Public Student(String n,String m)


  {


  Name=n;


  Major=m;


  }


  Public String toString()


  {


  Return getclass().getName()+”[name=”+major+”]”


  }


  Private String name;


  Private String major;


  }

就业数据资源平台