Quiz on 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

Correct Answer Is:


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 Is:


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

Correct Answer Is:


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

Correct Answer Is:


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 Is:


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 Is:


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 Is:


8. What File method creates a new disk directory?

a.    mkdir()
b.    makeDirectory()
c.    dir()
d.    list()

Correct Answer Is:


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

a.    delete()
b.    length()
c.    exists()
d.    This cannot be done.

Correct Answer Is:


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

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

a.    :
b.    \
c.    /
d.    .

Correct Answer Is:


The number you got right:       Percent Correct:       Letter Grade:   

Click here (If you have just 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 on reload to clear the old answers.)