on Reading Binary Files

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

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 Is:


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 Is:


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

a.    ReadInt()
b.    ReadInteger()
c.    readInt()
d.    read()

Correct Answer Is:


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 Is:


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 Is:


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 Is:


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

a.    byte
b.    Byte
c.    int
d.    null

Correct Answer Is:


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 Is:


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 Is:


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 Is:


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

Click here (If you have just 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 on reload to clear the old answers.)