Lab 5 – File I/O
Post
Test
|
Name: |
|
1. When f1.isFile() returns a
value of true, it means:
I.
f1 exists
II.
f1 is a directory
III.
f1 is not a directory
a. I
b. I & II
c. I & III
d. III
Answer: c
2. What is meant by the phrase current directory?
a.
The directory
where the Java compiler resides.
b.
The directory where the Java program resides.
c.
The directory
where the operating system resides.
d.
The C: drive.
Answer: b
3. In order to read data items from a file, a(n) ___________________ object must be attached to the file.
a. File
b. OutputStream
c. InputStream
d. None of the above
Answer: c
4.
The input/output package usually used with Java is:
5. The predefined console output, System.out, is an OutputStream object.
a. true
b. false
Answer: a
6.
Which of the following objects will produce a binary file?
I. FileOutputStream
II. PrintWriter
III. DataOutputStream
IV. BufferedWriter
a. I
& II b. II & IV c. I & III d. III&IV
Answer: c
7.
What is an advantage in using the PrintWriter class?
Answer:
b
Comprehension
8.
Suppose a file “New.txt” exists in the current directory and contains the
following text “abcdefg”. What is the result of executing the following code?
File outputFile = new File("New.txt");
FileWriter out = new
FileWriter(outputFile);
out.close();
a. New.txt will still contain
“abcdefg” because the file was not
written to before it was closed.
b. New.txt will be deleted.
c. A runtime error will occur.
d. New.txt will be overwritten
as an empty file.
e. None of the above
9.
You want to make a copy of a digital video file, named “MyVacation.dat”. Which
type of file handler should you use?
Answer: a
10.
At the end of a file access operation, what will happen if you forget to close
the file?
a. Your program will throw an
exception.
b. The file will be closed
automatically without losing any information.
c. The file will be closed
automatically losing unsaved information.
d. The file will be corrupted.
Answer: c