word格式
3) 设有如下代码: public void fun () { int i; try {
i=System.in.read ();
System.out.println(\ } catch (IOException e) {
System.out.println(\ } finally {
System.out.println(\ }
System.out.println(\}
如果有一个IOException发生, 则输出有哪些? A. Location 1 B. Location 2 C. Location 3 D. Location 4 4) 设有如下代码:
1 String s = null;
2 if ( s != null & s.length() > 0)
3 System.out.println(\ 4 if ( s != null && s.length() > 0)
5 System.out.println(\ 6 if ( s != null || s.length() > 0)
7 System.out.println(\ 8 if ( s != null | s.length() > 0)
9 System.out.println(\以下行中哪些会产生空指针异常。 A. 2,4 B. 6,8 C. 2,4,6,8 D. 2,6,8
5) 类Test1、Test2定义如下:
.. ..
word格式
1.public class Test1 {
2. public float aMethod(float a,float b) throws IOException { 3. } 4. }
5. public class Test2 extends Test1{ 6. 7. }
将以下哪种方法插入行6是不合法的。
A、float aMethod(float a,float b){ }
B、public int aMethod(int a,int b)throws Exception{ } C、public float aMethod(float p,float q){ }
D、public int aMethod(int a,int b)throws IOException{ } 6)设有如下代码: try {
tryThis(); return;
} catch (IOException x1) {
System.out.println(\ return;
} catch (Exception x2) {
System.out.println(\ return; } finally {
System.out.println(\ }
如果tryThis() 抛出 NumberFormatException,则输出结果是? A. 无输出
B. \后跟 \C. \后跟 \D. \E. \
十三、流式输入输出与文件处理
1)以下哪个是RandomAccessFile文件的构造方法: A.RandomAccessFile(\B.RandomAccessFile(\
.. ..
word格式
C.RandomAccessFile(\D.RandomAccessFile(\2)设有如下代码: import java.io.*; public class Th{
public static void main(String argv[]){ Th t = new Th(); t.amethod(); }
public void amethod(){ try{ ioCall();
}catch(IOException ioe){} } }
以下哪个最有可能是ioCall方法的方法体? A. public void ioCall () throws IOException{
DataInputStream din = new DataInputStream(System.in); din.readChar(); }
B. public void ioCall () throw IOException{
DataInputStream din = new DataInputStream(System.in); din.readChar(); }
C. public void ioCall (){
DataInputStream din = new DataInputStream(System.in); din.readChar(); }
D. public void ioCall throws IOException(){
DataInputStream din = new DataInputStream(System.in); din.readChar(); }
3)当前目录不存在名为Hello.txt的文件,执行下面代码的输出结果为? import java.io.*; public class Mine{
.. ..
word格式
public static void main(String argv[]){ Mine m=new Mine( );
System.out.println(m.amethod()); }
public int amethod(){ try{
FileInputStream file=new FileInputStream(\ }
catch(FileNotFoundException e){
System.out.print(\ return -1; }
catch(IOException e){
System.out.print(\ } return 0; } }
A. No such file found B. No such file found-1
C. No such file foundDoing finally-1 D. 0
4) 使用哪个类可创建目录?
A. File B. DataOutput C. Directory D. FileDescriptor E. FileOutputStream
5) 假设raf是一个随机访问文件,以下语句的编译和运行结果为?raf.seek( raf.length() ); A.代码不能编译. B.会出现IOException
C.文件指针将定位到文件的最后一个字符之前 D.文件指针将定位到文件的最后一个字符
6)以下哪些是FileOutputStream 构造方法的合法形式? A. FileOutputStream( FileDescriptor fd ) B. FileOutputStream( String n, boolean a ) C. FileOutputStream( boolean a )
.. ..