revised: 10/05/03


Quiz on the File Class

This is a practice quiz. The results are not recorded anywhere and do not affect your grade. The questions on this quiz might not appear in any quiz or test that does count toward your grade.

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 package holds the File class?

A.    java.io
B.    java.file
C.    java.util
D.    java.lang

2. Does constructing a File object automatically create a disk file?

A.    No—a File object is an interface to a file or directory which might not actually exist.
B.    No—if the file already exists it is not created; otherwise it is.
C.    Yes—the File object contains all the data of the file in memory can can be used in place of the disk file.
D.    Yes—constructing a File object always creates a new file.

3. The path name of a file is given by:

C:\MyFiles\Programs\Examples\someFile.txt
Is this a relative or an absolute path name?

A.    relative
B.    absolute
C.    both
D.    neither

4. The path name of a file is given by:

C:\MyFiles\Programs\Examples\someFile.txt
What is the absolute path name of the directory the file is located in?

A.    Examples
B.    ..\Examples\someFile.txt
C.    C:\
D.    C:\MyFiles\Programs\Examples

5. What method of File is used to test if a file or directory exists?

A.    isFile()
B.    isDirectory()
C.    list()
D.    exists()

6. A program uses the FileWriter constructor with the string "newFile.txt". What happens if "newFile.txt" already exists?

A.    An exception is thrown.
B.    The constructor returns null.
C.    The program exits.
D.    The existing file is erased and replace with a new, empty one.

7. Will the following code compile correctly?

File file = new File("temp.txt");
FileReader in = new FileReader( file );

A.    No—the constructor for FileReader is used incorrectly.
B.    No—the constructor for File must have an absolute path name.
C.    Yes—the syntax is correct.
D.    Yes—the compiler will check that "temp.txt" already exists.

8. What File method creates a new disk directory?

A.    mkdir()
B.    makeDirectory()
C.    dir()
D.    list()

9. What File method is used to remove a file?

A.    delete()
B.    length()
C.    exists()
D.    This cannot be done.

10. In the following, what is the directory separator character?

C:\MyFiles\Programs\Examples\someFile.txt 

A.    :
B.    \
C.    /
D.    .

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.