Java OCA OCP Practice Question 3061

Question

Choose the correct option based on this code segment:

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);
}
a)   this code segment throws a PatternSyntaxException
b)   this code segment throws an UnsupportedOperationException
c)   this code segment throws an InvalidArgumentException
d)   this code segment lists the files ending with suffix .java in the current directory


d)

Note

the path "." specifies the current directory. the pattern "*.{java}" matches file names with suffix .java.




PreviousNext

Related