Exam 1z0-809 All QuestionsBrowse all questions from this exam
Question 191

Given the code fragment:

Stream files = Files.list(Paths.get(System.getProperty("user.home"))); files.forEach (fName -> { //line n1 try {

Path aPath = fName.toAbsolutePath(); //line n2

System.out.println(fName + ":"

+ Files.readAttributes(aPath, Basic.File.Attributes.class).creationTime

());

} catch (IOException ex) {

ex.printStackTrace();

});

What is the result?

    Correct Answer: D

    The code contains a compilation error at line n2 because the class name should be BasicFileAttributes instead of Basic.File.Attributes. This typo will cause the code to fail to compile.

Discussion
jduarteOption: A

A is correct.

steefaandOption: C

C is correct assuming typos.

petetsaiOption: B

Basic package dosen't exsist... readAttributes will fail to compile.

WilsonKKerll

import java.nio.file.attribute.BasicFileAttributes;

Huim

What's the difference between A and C?

Svetleto13

They are 2 similar questions use walk() and list() methods.We use list() in this one and thats why answer is C.The main difference between walk() and list is that list(dir) gives a stream of files in the directory dir , while walk() method walk the subtree of its argument including the root of subtree—the directory itself.I hope this is useful.