Java OCA OCP Practice Question 2612

Question

Consider the following program:

import java.io.IOException;
import java.nio.file.*;
class Main {//from w ww . ja v  a 2s  . co m
        public static void main(String []args) {
                Path currPath = Paths.get(".");
         try (DirectoryStream<Path> javaFiles = Files.newDirectoryStream
         (currPath, "*.{java}")) {
                 for(Path javaFile : javaFiles) {
                         System.out.println(javaFile);
                 }
         } catch (IOException ioe) {
                 System.err.println("IO Error occurred");
                 System.exit(-1);
         }
 }
}

Which one of the following options correctly describes the behavior of this program?

  • a) This program throws a PatternSyntaxException.
  • b) This program throws an UnsupportedOperationException.
  • c) This program throws an InvalidArgumentException.
  • d) This program lists the files ending with suffix .java in the current directory.


d)

Note

The path "." specifies the current directory.

The glob pattern "*.{java}" matches file names with suffix .java.




PreviousNext

Related