0% found this document useful (0 votes)
39 views3 pages

Chapter One Questions

The document contains 10 multiple choice questions about character output streams, FileWriter, and BufferedWriter in Java. Question 1 asks about the abstract class that is the ancestor of all character output streams, with the answer being Writer. Question 2 describes what the FileWriter constructor does, with the answer being that it will create a new file or open an existing one for appending. Question 3 addresses the number of bytes used to store characters from the English alphabet in a program versus on disk, with the answer being 1 byte in a program and 2 bytes on disk.

Uploaded by

TEGEGN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Chapter One Questions

The document contains 10 multiple choice questions about character output streams, FileWriter, and BufferedWriter in Java. Question 1 asks about the abstract class that is the ancestor of all character output streams, with the answer being Writer. Question 2 describes what the FileWriter constructor does, with the answer being that it will create a new file or open an existing one for appending. Question 3 addresses the number of bytes used to store characters from the English alphabet in a program versus on disk, with the answer being 1 byte in a program and 2 bytes on disk.

Uploaded by

TEGEGN
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

1. What is the abstract class that is the ancestor of all character output streams?

a. Writer
b. OutputStream
c. FileWriter
d. BufferedWriter
A

2. What does the following constructor do: FileWriter fw = new


FileWriter( "myFile.txt" );
a. It creates the textfile "myFile.txt" in the root directory.
b. It creates the textfile "myFile.txt" unless it already exists.
c. Any previous "myFile.txt" in the current directory will be deleted and a new one created.
d. A new "myFile.txt" will be created in the current directory, or a previous one will be
opened for appending.
C

3. For characters from the English (Roman) alphabet, how many bytes are used per
character in the Program and how many are used on a disk file?
a. program: 1 disk file: 1
b. program: 1 disk file: 2
c. program: 2 disk file: 1
d. program: 2 disk file: 2
C

4. What does closing a file do?


a. Flushes pending output and finishes processing the file.
b. Finishes processing the file, only.
c. Flushes pending output, but the file may still be written to.
d. Makes the file read-only.
A

5. When a file is opened for appending where does write() put new text?
a. At the beginning of the file.
b. At the end of the file.
c. Where ever the user specifies.
d. Files cannot be appended to.
B

6. What happens if a FileWriter constructor is given an illegal file name?


a. The program bombs immediately.
b. The users disk is corrupted.
c. The constructor returns a null value.
d. An IOException is thrown.
D

7. What class should be used to buffer the characters sent to a FileWriter stream?
a. BufferedFileWriter
b. BufferedWriter
c. Writer
d. Buffer
B

8. What method a buffered character stream sends the correct characters for
terminating a line of text on the computer running the program?
a. buf.write("\n");
b. buf.writeLine();
c. buf.newLine();
d. buf.putLine();
C

9. What method ensures that data from previous calls to write() is sent to disk and
leaves the file open?
a. flush()
b. close()
c. Each write() does this for the previous one.
d. print()
A
10. Can a text file written by a Java program be read by programs written in other
languages?
a. No---Java uses its own text file format.
b. No---the ends of lines will be completely different.
c. Yes---usually there will be no problem.
d. Yes---this is always possible without any problems.
C

You might also like