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.
For me C also works. after running the code I ve got ACD is the answer
here is the code I used :
// inside method or main whatever, please choose an appropriate folder :
Path p = Paths.get(“d:\\Project\\Company”);
try {
DirectoryStream ds = Files.newDirectoryStream(p, “*.{java,html,jar}”);
System.out.println(“*.{java,html,jar}”);
for (Path entry : ds) {
System.out.println(entry.getFileName());
}
ds.close();
System.out.println(“*.{java*,html*,jar*}”);
ds = Files.newDirectoryStream(p, “*.{java*,html*,jar*}”);
for (Path entry : ds) {
System.out.println(entry.getFileName());
}
ds.close();
System.out.println(“*.[java,html,jar]”);
ds = Files.newDirectoryStream(p, “*.[java,html,jar]”);
for (Path entry : ds) {
System.out.println(entry.getFileName());
}
ds.close();
System.out.println(“**.{java,html,jar}”);
ds = Files.newDirectoryStream(p, “**.{java,html,jar}”);
for (Path entry : ds) {
System.out.println(entry.getFileName());
}
ds.close();
} catch (Exception e) {
}
/////////////////////////
C is not correct, because we do not have the exact extentions .java, we could have .java_plus_any_other_string
A, C, D . tested