Given the code fragment:
public class Test {
public static void main(String[] args) {
Path dir = Paths.get(“D:\\company”);
//insert code here. Line ***
for (Path entry: stream) {
System.out.println(entry.getFileName());
}
} catch (IOException e) {
System.err.println(“Caught IOException: ” + e.getMessage());
}
}
Which two try statements, when inserted at line ***, enable you to print files with the extensions.java, .htm, and .jar.
A.
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir,”*.{java, htm,jar}”)){
B.
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir,”*. [java, htm, jar]”)) {
C.
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir,”*.{java*, htm*, jar*}”)) {
D.
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir,”**.{java, htm, jar}”)) {
Explanation:
“*. {java, htm, jar}and “**. {java, htm, jar}will match any file with file endings java, htm, or jar.
C also finds the same files
Yes A,C and D are OK.
My advice here is when you will see the right code(exam) check the spaces here
java, htm,jar
|
|
this space makes to change the output
java,(space)htm,(this space too)jar
thanks for the advice about the spaces
C is not correct, because we do not have the exact extentions .java, we could have .java_plus_any_other_string
+1
A and D are ok
The answer is A and D.