Lab 5 – File I/O

Post Test

 

 

Name:

 

 

Knowledge/Memory

 

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:

 

  1. java.file
  2. java.input
  3. java.inout
  4. java.io

 

Answer: d

 

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?

 

  1. It initializes the printer, and buffers the print file.
  2. Its methods use the appropriate line termination character for your operating system.
  3. It transforms character to print format.
  4. It connects directly to a disk file without using any other stream.

 

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

 

Answer: d

 

 

9. You want to make a copy of a digital video file, named “MyVacation.dat”. Which type of file handler should you use? 

 

  1. A byte stream handler
  2. A character stream handler
  3. Either a byte stream handler or a character stream handler
  4. None of the input/output stream handlers can be used to copy a digital video file

 

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