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

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.

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.



Leave a Reply 8

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


Marian

Marian

C also finds the same files

iThKaRoh

iThKaRoh

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

iThKaRoh

iThKaRoh

java,(space)htm,(this space too)jar

Luiz

Luiz

thanks for the advice about the spaces

Eloi

Eloi

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

Eloi

Eloi

A and D are ok

Surfo

Surfo

The answer is A and D.