Oracle
1Z0-805 · Question #18
Given the code fragment: public static void main(String[] args) { Path dir = Paths.get("d:\\company"); // insert code here. Line ** for (Path entry: stream) {…
The correct answer is A. try (DirectoryStream<path> stream =Files.newDirectoryStream(dir, "*.{java, htm, jar}")) { D. try (DirectoryStream<path> stream =Files.newDirectoryStream(dir, "**.{java, htm, jar}")) {. See the full explanation below for the reasoning.
Question
Given the code fragment:
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 11, enable you to print files with the extensions.java, .htm, end and .jar.
Options
- Atry (DirectoryStream<path> stream =Files.newDirectoryStream(dir, "*.{java, htm, jar}")) {
- Btry (DirectoryStream<path> stream =Files.newDirectoryStream(dir, "*.[java, htm, jar"] }} {
- Ctry (DirectoryStream<path> stream =Files.newDirectoryStream(dir, ".{java, htm*, jar*}"}} {
- Dtry (DirectoryStream<path> stream =Files.newDirectoryStream(dir, "**.{java, htm, jar}")) {
How the community answered
(40 responses)- A75% (30)
- B18% (7)
- C8% (3)
Community Discussion
No community discussion yet for this question.