Given the code fragment: Which two try statements, when inserted at line ***, enable you to print files with the extensions.java, .htm, and .jar.

Given the code fragment:

Which two try statements, when inserted at line ***, enable you to print files with the
extensions.java, .htm, and .jar.

Given the code fragment:

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.



Leave a Reply 3

Your email address will not be published. Required fields are marked *


BKhateib

BKhateib

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) {

}
/////////////////////////

Luiz

Luiz

C is not correct, because we do not have the exact extentions .java, we could have .java_plus_any_other_string

wolfatthegate

wolfatthegate

A, C, D . tested