Lab 5 – File I/O

Pre Test

 

 

Name:

 

 

 

Knowledge/Memory

 

1.       What method is called to get only the name of a file?

 

a.      getAbsolutePath()

b.      getFile()

c.       getName()

d.     getFilename()

 

Answer: c

 

2.       Text files are generally stored in which format?

 

a.      Binary format

b.      ASCII format

c.       EBDIC format

d.     GIF format

 

Answer: b

 

3.       What is a buffer?

 

a.      A temporary holding place for data.

b.      A file containing binary data.

c.       A stream that deals with character IO.

d.     A means for entering data.

 

Answer: a

 

4.       What is meant by the phrase data caching?

 

a.      Saving data to permanent memory.

b.      Saving data to a file.

c.       Saving data as a block to a temporary holding place.

d.     Saving data to an output stream.

 

Answer: c

 

5.       Which of the following statements is not true about binary files?

 

a.      An executable program is stored as a binary file.

b.      A binary file is human readable.

c.       A binary file is used to store graphics and sound.

d.     A program that processes the binary file must know exactly how it is laid out in order to make use of it.

 

Answer: b

 

6.       What is a random access file?

 

I.          A file that can be read from any specified location in the file.

II.         A file that can be written to at any specified location in the file.

III.       A file that must be written and read sequentially but can be opened randomly.

IV.       A file that can be searched randomly.

 

a.      I

b.      II

c.       I & II

d.     I & IV

e.      III & IV

Answer: c

 

Comprehension:

 

7.       Which of the following statements is true about the File class?

 

a. The File class provides a general machine-independent interface to the file system.

b. The File class is meant for handling the contents of files.

c. The File class cannot be used to handle directories.

d. When you create a File object, you automatically create a file or directory based on the pathname specified.

Answer: a

 

8. Which of the following statements is true about a stream?

 

I.        A stream is simply a sequence of data items.

II.     A stream is always associated with a file.

III.   A stream has either a source or destination, but not both.

IV.  A stream can be used to read data from the console.

 

a.                   I, III, & IV

b.                   I, II, & III

c.                   I, II, III, & IV

d.                   III & IV

e.                   II, III, & IV

 

Answer: a

 

9. Which of the following types of errors may be generated while operating on a file?

 

a.       File not found.

b.       File cannot be written to.

c.       Unexpected End-Of-File (EOF).

d.       All the above.

 

Answer: d

 

10. What are the possible causes of a “FileNotFound” exception?

I.          The file is opened for writing but is a read-only file.

II.         The file path specified does not lead to the file.

III.       The file has already been opened by another program.

IV.       The file has an invalid or unreadable format.

V.        The file does not exist.

 

a.   I, II, & V

b.   II, IV, & V

c.   II & III

d.   II & V

e.   I, III, & V

 

Answer: a