revised: 10/05/03, 11/07/2012, 10/14/2017

Quiz File on Reading Binary Files

Instructions: For each question, choose the single best answer. Make your choice by clicking on its button. You can change your answers at any time. When the quiz is graded, the correct answers will appear in the box after each question.

1. What abstract data type is the ancestor of all streams that input byte-oriented data?

A.    InputStream

B.    ByteInputStream

C.    BufferedByteInputStream

D.    ByteReader

Correct Answer:

2. Which of the following opens the file "myData.stuff" for Input?

A.    FileInputStream fis = new FileInputStream( "myData.stuff", true)

B.    FileInputStream fis = new FileInputStream( "myData.stuff")

C.    DataInputStream dis = new DataInputStream( "myData.stuff" )

D.    FileInputStream fis = new FileInputStream( new BufferedInputStream( "myData.stuff") )

Correct Answer:

3. What is the DataInputStream method that reads an int value?

A.    ReadInt()

B.    ReadInteger()

C.    readInt()

D.    read()

Correct Answer:

4. Say that a file was created using many calls to DataOutputStream.writeInt(). Is it possible to read that file with DataInputStream.readDouble()?

A.    No – the hardware will not let this happen.

B.    No – the compiler will not let this happen.

C.    Yes – although the results almost certainly will be wrong.

D.    Yes – nothing wrong in doing that.

Correct Answer:

5. In practice, is it always possible to know how to interpret the bytes in a given file?

A.    No – because byte patterns can mean almost anything and often documentation is poor or missing.

B.    No – files from one type of computer can't be read by any other type.

C.    Yes – data and file formats are the same with all programs on all computers.

D.    Yes – all you need to do is try all possible interpretations until you find the one that works.

Correct Answer:

6. Is input and output with binary files slower or faster than with character-oriented files?

A.    Slower―because primitive data take more memory that characters.

B.    Slower―because primitive data must be translated into characters when doing IO.

C.    Faster―because binary data does not use a buffer.

D.    Faster―because binary data is more compact and does not need translation.

Correct Answer:

7. What data type does DataInputStream.readUnsignedByte() evaluate to?

A.    byte

B.    Byte

C.    int

D.    null

Correct Answer:

8. What happens when DataInputStream.readLong() reaches the end of the input file?

A.    Control automatically leaves the program.

B.    A null value is returned.

C.    The program crashes.

D.    An EOFException is thrown.

Correct Answer:

9. It it possible to make a copy of a file without knowing the format of the data it contains?

A.    No – you must know what each byte means in order to copy it to a file.

B.    No – files must have a header that describes the rest of the bytes.

C.    Yes―any file can be copied as long as all the data is the same type.

D.    Yes―a byte-by-byte copy works for all data.

Correct Answer:

10. What happens when the constructor for FileInputStream fails to open a file for reading?

A.    It returns null.

B.    It throws a FileNotFoundException.

C.    It throws a DataFormatException.

D.    It throws a ArrayIndexOutOfBoundsException.

Correct Answer:

The number you got right:       Percent Correct:       Letter Grade:   

Click here If you have returned here from another page, or have re-loaded this page, you will need to click again on each of your choices for the grading program to work correctly. You may want to press the SHIFT KEY while clicking to clear the old answers.