Created 07/09/02; revised 08/20/2011, 11/07/2012

Quiz on Writing Text 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 is the ancestor class of streams that do character-oriented output?

A.    Writer

B.    Reader

C.    Stream

D.    Object

2. How many bits per character does a Java program use?

A.    4

B.    8

C.    16

D.    32

3. What is the class that translates characters from the internal form (used by a Java program) to the external form (used by a disk file).

A.    FileWriter

B.    BufferedWriter

C.    PrintWriter

D.    Writer

4. What is the disk file format for characters that is intended to work for all human languages?

A.    UTF


C.    ANSI


5. Which of the following opens an existing file myFile.txt so that characters may be added to its end?

A.    FileWriter fw = new FileWriter("myFile.txt");

B.    FileWriter fw = new FileWriter("myFile.txt", true);

C.    FileWriter fw = new FileWriter("myFile.txt", false);

D.    FileWriter fw = new FileWriter("myFile.txt", FileWriter.APPEND);

6. What does the flush() method of a stream do?

A.    It erases all the data in the file.

B.    It initializes the output methods.

C.    It summons the garbage collector.

D.    It ensures that all pending output operations are completed.

7. What is a buffer?

A.    A section of main memory used as a work area for input or output operations.

B.    A temporary disk file.

C.    A method that transforms data into an external format.

D.    The character or characters at the end of a line of text.

8. What is an advantage in using the PrintWriter class?

A.    It initializes the printer, and buffers the print file.

B.    It transforms characters to print format.

C.    Its methods use the approprate line termination character for your operating system.

D.    It connects directly to a disk file without using any other streams.

9. Does the println() method of PrintWriter throw exceptions?

A.    No. No methods of PrintWriter throw exceptions.

B.    Yes. It throws an IOException.

C.    Yes. It throws an PrintException.

D.    Yes. It throws a DataFormatException.

10. Which operation is usually more reliable: input or output?

A.    Input.

B.    Output.

C.    Neither.

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.