niusouti.com

(读写文件)下列语句执行时,若文件”customer.dat”不存在,则会产生的异常是________。 FileInputStream fis = new FileInputStream(“customer.dat”);A.ArithmeticExceptionB.NullPointerExceptionC.EOFExceptionD.FileNotFoundException

题目

(读写文件)下列语句执行时,若文件”customer.dat”不存在,则会产生的异常是________。 FileInputStream fis = new FileInputStream(“customer.dat”);

A.ArithmeticException

B.NullPointerException

C.EOFException

D.FileNotFoundException


相似考题
更多“(读写文件)下列语句执行时,若文件”customer.dat”不存在,则会产生的异常是________。 FileInputStream fis = new FileInputStream(“customer.dat”);”相关问题
  • 第1题:

    请完成下列Java程序:实现打印出自己的源文件的功能。

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

    import java.io.*;

    import java.util.StringTokenizer;

    public class ex27_2{

    public static void main(String args[])throws IOException{

    FileInputStream fis=new FileInputStream("ex27_2.java");

    DataInputStream dis=new DataInputStream(fis);

    String str=null;

    while(true){

    __________________;

    if(str==null){

    __________________;

    }

    StringTokenizer st=new StringTokenizer(str);

    while(st.hasMoreTokens()){

    System.out.print(st.nextToken()+ " " );

    }

    System.out.println();

    }

    }

    }


    正确答案:str=dis.readLine() break
    str=dis.readLine() break 解析:本题主要考查文件I/O操作和while语句,if语句的使用。解题关键是熟悉文件I/O操作的基本方法,以及利用while语句和if语句控制程序流程。本题中,第1个空,DataInputStream的对象dis调用readLine()方法,从输入流中读取数据,并写给String类的str对象;第二空,如果str为空,则跳出循环体,这里使用break完成跳转。

  • 第2题:

    下列程序要求将source.txt文件中的字符,通过文件输入/输出流复制到另一个dest.txt文件中。请将程序补充完整。

    注意:不改动程序结构,不得增行或删行。

    import java.io.*;

    public class ex2

    {

    public static void main(String[] args) throws IOException

    {

    File inputFile;

    File outputFile;

    FileInputStream in;

    FileOutputStream out;

    int c;

    inputFile=new File("source.txt");

    utputFile=new File("dest.txt");

    in=new FileInputStream(inputFile);

    ______(outputFile);

    while((c=in.read())!=-1)

    ______;

    in.close();

    out.close();

    }

    }


    正确答案:out=new FileOutputStream out.write?
    out=new FileOutputStream out.write? 解析:本题主要考查Java中的IO操作。第一空应填写out=new FileOutputStream。Java中要将一个文件中的内容写入到另一个文件中,需要知道文件读写操作。程序中已经声明了FileInputStream的对象in,套接File类的对象inputFile来进行读入的操作,我们还需要声明 FileOutputStream类的对象out,来套接File类的对象outputFile进行读出的操作。第二空应填写out.write(c)。程序此处要求进行文字写入。在程序的前一个步骤,已经调用FileInputStream类的read方法,将文件中的内容以单字节的方式读入到流中,所以我们在这里要调用FileOutputStream类的write方法,将流中的内容写出。

  • 第3题:

    要从“file.dat”文件中读出第10个字节存到变量C中,下列______方法是合适的。

    A.FileInputStream in=new FileInputStream("file.dat");in.skip(9);int c=in.read( );

    B.FileInputStream in=new FileInputStream("file.dat");in.skip(10);int c=in.read( );

    C.FileInputStream in=new FileInputStream("file.dat");int c=in.read( );

    D.RandomAccessFile in=new RandomAccessFile("file.dat");in.skip(9);int c=in.readByte( );


    正确答案:A
    解析: Java提供FileInputStream是将文件以流的方式读取,它是按照文件顺序从位置0开始读取的,RandomAccessFile是随机读取数据的;读取位置不一定从0开始,可以使用skip(n)方法来跳过n个字符,通过readByte( )方法读取一个字符,通过read( )方法可以读取输入流中的一个字符。所以要从第10个字节开始读取,应该用skip(10)方法,所以选项A正确。

  • 第4题:

    下列程序实现对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()


    正确答案:A
    解析:本题考查Java类实现zip数据压缩方式。zip压缩文件结构:一个zip文件由多个entry组成,每个entry有一个惟一的名称,entry的数据项存储压缩数据。ZipInputStream实现了zip压缩文件的读输入流,支持压缩和非压缩entry。题目程序中FileInputStreamfis=newFileInputStream("test/file,zip")构造了—个文件输入流,ZipInputStreamzis=newZipInputStream(fis)语句利用文件输入流fis构造了一个ZIP输入流,zis.getNextEntry()语句返回ZIP文件中的下一个entry,井将输出流定位在此entry数据项的起始位置,

  • 第5题:

    下列代码实现从文件file.dat中读出第5个字节到变量c中,横线处应该填入下列项中的______。 import java.io.*; public class exl5 { public static void main(String[] args) { try System.out.println((char)c); catch(Exception e) { e.printStackTrace(); } } }

    A.FileInputStream in = new FileInputStream("chl/file.dat"); in.skip(4); int c = in.read();

    B.FileInputStream in = new FileInputStream("chl/file.dat"); in.skip(5); int c = in.read();

    C.Fi2eInputStream in = new FileInputStream("file.dat"); int c = in.read();

    D.RandomAccessFile in = new RandomAccessFile ("chi/file. dat "); in.skip (4); int c = in.readByte();


    正确答案:A

  • 第6题:

    在J2EE中,利用下列构造函数准备对文件abc.txt操作,但文件abc.txt在当前目录不存在,不会产生运行时错误的是()。 

    • A、BufferedReader  breader=new BufferedReader(new FileReader("abc.txt"));
    • B、PrintWriter out = new PrintWriter(new FileWriter(“abc.txt”),true);
    • C、FileInputStream fin = new FileInputStream(“abc.txt”);
    • D、OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(“abc.txt”));

    正确答案:B,D

  • 第7题:

    什么情况下创建FileInputStream对象可能引发IOException?什么情况下创建FileOutputStream对象可能破坏文件?


    正确答案:当你创建一个输入流而文件不存在时,引发FileNotFoundException异常,使用FileInputStream的reset()会生成IOException异常。对于输出流,如果文件不能生成,则引发FileNotFoundException异常,打开一个只读文件,会引发一个IOException异常。如果一个输出文件被打开,所有原先存在的同名的文件被破坏。

  • 第8题:

    下列属于文件输入输出类的是()

    • A、 FileInputStream和FileOutputStream
    • B、 BufferInputStream和BufferOutputStream
    • C、 PipedInputStream和PipedOutputStream
    • D、 以上都是

    正确答案:D

  • 第9题:

    Which two create an InputStream and open file the “file.txt” for reading? ()

    • A、 InputStream in=new FileReader(“file.txt”);
    • B、 InputStream in=new FileInputStream(“file.txt”);
    • C、 InputStream in=new InputStreamFileReader (“file.txt”, “read”);
    • D、 FileInputStream in=new FileReader(new File(“file.txt”));
    • E、 FileInputStream in=new FileInputStream(new File(“file.txt”));

    正确答案:B,E

  • 第10题:

    多选题
    在J2EE中,利用下列构造函数准备对文件abc.txt操作,但文件abc.txt在当前目录不存在,不会产生运行时错误的是()。
    A

    BufferedReader  breader=new BufferedReader(new FileReader(abc.txt));

    B

    PrintWriter out = new PrintWriter(new FileWriter(“abc.txt”),true);

    C

    FileInputStream fin = new FileInputStream(“abc.txt”);

    D

    OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(“abc.txt”));


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

  • 第11题:

    单选题
    要从文件" file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合? ()
    A

     FileInputStream in=new FileInputStream(file.dat); in.skip(9); int c=in.read();

    B

     FileInputStream in=new FileInputStream(file.dat); in.skip(10); int c=in.read();

    C

     FileInputStream in=new FileInputStream(file.dat); int c=in.read();

    D

     RandomAccessFile in=new RandomAccessFile(file.dat); in.skip(9); int c=in.readByte();


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

  • 第12题:

    单选题
    在J2ee中,以下各项中,()正确阐述了创建InputStreamReader的方式。
    A

    new InputStreamReader(new FileInputStream(data));

    B

    new InputStreamReader(new FileReaderdata));

    C

    new InputStreamReader(new BufferedReader(data));

    D

    new FileInputStream(data)


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

  • 第13题:

    在读字符文件emplyee.dat时,使用该文件作为参数的类是( )。

    A.BufferReader

    B.DataInputStream

    C.DataOutputStream

    D.FileInputStream


    正确答案:D
    解析:字节输入流继承自InputSteam类,并且使用DataInputStream实现DataInput接口。编程时的步骤如下:字节数据的来源(二进制文件)作为FileInputStream的构造方法的参数,实例化一个FileInputStream对象;FileInputStream对象作为DataInputStream的构造方法的参数;然后就可以使用InputStream类中的方法,进行字节输入流的操作。

  • 第14题:

    下面程序实现对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( )


    正确答案:A
    解析: zip压缩文件结构:一个zip文件由多个entry组成,每个entry都有唯一的名称, entry的数据项存储压缩数据。ZipInputStream实现zip压缩文件的读输入流,支持压缩和非压缩entry。题目程序中构造了一个文件输入流fis,然后用fis构造一个zip输入流,zis.getNextEntry( )语句返回zip文件中的下一个entry,并将输出流定位在此entry数据项的起始位置。

  • 第15题:

    下列程序实现对ZIP文件file.zip的检索,在横线处 填入正确的语句( )。 package test; importjava.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 ZiplnputStream(fis); ZipEntry an; while(( )!=null){ en.getName; zis.closeEntry; } zis.close: } catch(Exception e){ printStackTrace; } } }

    A.en=zis.getNextEntry

    B.en= =zis.getNextEntry

    C.en=zis.getEntry

    D.zis.getNextEntry


    正确答案:A
    A。【解析】本题考查Java类实现ZIP数据压缩方式。ZIP压缩文件结构:一个ZIP文件由多个Entry组成,每个Entry有一个唯一的名称,Entry的数据项存储压缩数据。ZiplnputStream实现了ZIP压缩文件的读输入流,支持压缩和非压缩Entry.题目程序中FileInputStreallD_fis=newFilelnputStream("test/file.zip")构造了一个文件输入流,ZiplnputStreamzis=newZiplnputStream(fis)语句利用文件输入流fis构造了一个ZIP输入流,zis.getNextEntry语句返回ZIP文件中的下一个Entry,并将输出流定位在此entry数据项的起始位置.

  • 第16题:

    要从文件“file.dar”文件中读出第10个字节到变量C中,下列哪个方法适合 ( )

    A.FileInputStream in=new FileInputStream("file.dar");in.skip9.;int c=in.read();

    B.FileInputStream in=new FileInputStream("file.dar");in.skip10.;int c=in.read();

    C.FileInputStream in=new FileInpmStream("file.dar");int c=in.read();

    D.Random AccessFile in=new RandomAceessFile("file.dar");in.skip9.;int c=in.readByte


    正确答案:A

  • 第17题:

    在J2ee中,以下各项中,()正确阐述了创建InputStreamReader的方式。 

    • A、new InputStreamReader(new FileInputStream("data"));
    • B、new InputStreamReader(new FileReader"data"));
    • C、new InputStreamReader(new BufferedReader("data"));
    • D、new FileInputStream("data")

    正确答案:A

  • 第18题:

    要从文件" file.dat"文件中读出第10个字节到变量C中,下列哪个方法适合? ()

    • A、 FileInputStream in=new FileInputStream("file.dat"); in.skip(9); int c=in.read();
    • B、 FileInputStream in=new FileInputStream("file.dat"); in.skip(10); int c=in.read();
    • C、 FileInputStream in=new FileInputStream("file.dat"); int c=in.read();
    • D、 RandomAccessFile in=new RandomAccessFile("file.dat"); in.skip(9); int c=in.readByte();

    正确答案:D

  • 第19题:

    FileInputStream和FileOutputStream错误的是()

    • A、是字节流
    • B、是节点流
    • C、用其拷贝文件时,不能拷贝中文
    • D、可以拷贝任何文本文件和2进制文件

    正确答案:C

  • 第20题:

    要从文件"file.dat"中读出第10个字节到变量c中,下列哪个方法适合?()

    • A、FileInputStream in=new FileInputStream("file.dat");in.skip(9);intc=in.read()
    • B、FileInputStream in=new FileInputStream("file.dat");in.skip(10);intc=in.read()
    • C、FileInputStream in=new FileInputStream("file.dat");intc=in.read()
    • D、RandomAccessFile in=new RandomAccessFile("file.dat");in.skip(9);intc=in.readByte()

    正确答案:D

  • 第21题:

    下面哪个类不能直接读取磁盘文件()

    • A、FileReader
    • B、RandomAccessFile
    • C、FilterReader
    • D、FileInputStream

    正确答案:C

  • 第22题:

    多选题
    Which two create an InputStream and open file the “file.txt” for reading? ()
    A

    InputStream in=new FileReader(“file.txt”);

    B

    InputStream in=new FileInputStream(“file.txt”);

    C

    InputStream in=new InputStreamFileReader (“file.txt”, “read”);

    D

    FileInputStream in=new FileReader(new File(“file.txt”));

    E

    FileInputStream in=new FileInputStream(new File(“file.txt”));


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

  • 第23题:

    单选题
    要从文件"file.dat"中读出第10个字节到变量c中,下列哪个方法适合?()
    A

    FileInputStream in=new FileInputStream(file.dat);in.skip(9);intc=in.read()

    B

    FileInputStream in=new FileInputStream(file.dat);in.skip(10);intc=in.read()

    C

    FileInputStream in=new FileInputStream(file.dat);intc=in.read()

    D

    RandomAccessFile in=new RandomAccessFile(file.dat);in.skip(9);intc=in.readByte()


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

  • 第24题:

    单选题
    下列属于文件输入输出类的是()
    A

     FileInputStream和FileOutputStream

    B

     BufferInputStream和BufferOutputStream

    C

     PipedInputStream和PipedOutputStream

    D

     以上都是


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