Java OCA OCP Practice Question 2469

Question

Given a directory structure:

- baseDir  
  - testDir  
    - subDir2  
      - Data.txt 

and given the following code:.

12.   String name = "testDir" + File.pathSeparator + "subDir2"   
                 + File.pathSeparator + "Data.txt";  
13.   File f = new File(name);  
14.   System.out.println("exists " + f.exists()); 

Assuming the proper import statements and exception handling, which statements must be true in order for the output to be "exists true"? (Choose three.).

A.   Line 12 is correct as it stands.
B.   Line 14 is correct as it stands.
C.   The program must be invoked from the baseDir directory.
D.   The program must be invoked from the testDir directory.
E.   Line 12 must use File.separator instead of File.pathSeparator
F.   Line 14 must use the method fileExists() instead of exists()


B, C, and E are correct.

Note

In order to find the Data.txt file the program must be invoked from the baseDir directory.

The pathSeparator field in the File class is used to separate path lists, not directories in paths, and the correct method is File.exists().




PreviousNext

Related