revised: 10/05/03, 10/01/11, 11/07/2012, 10/14/2017

Quiz on the File Class

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?


B.    java.file

C.    java.util

D.    java.lang

Correct Answer:

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.

Correct Answer:

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


Is this a relative or an absolute path name?

A.    relative

B.    absolute

C.    both

D.    neither

Correct Answer:

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


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

Correct Answer:

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

A.    isFile()

B.    isDirectory()

C.    list()

D.    exists()

Correct Answer:

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.

Correct Answer:

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.

Correct Answer:

8. What File method creates a new disk directory?

A.    mkdir()

B.    makeDirectory()

C.    dir()

D.    list()

Correct Answer:

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

A.    delete()

B.    length()

C.    exists()

D.    This cannot be done.

Correct Answer:

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


A.    :

B.    \

C.    /

D.    .

Correct Answer:

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.