What is the result?

Given the code fragment:
Stream<Path> files = Files.walk(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?

Given the code fragment:
Stream<Path> files = Files.walk(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?

A.
All files and directories under the home directory are listed along with their attributes.

B.
A compilation error occurs at line n1.

C.
The files in the home directory are listed along with their attributes.

D.
A compilation error occurs at line n2.



Leave a Reply 5

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


smh

smh

need help on this one. the code compiles but still gives Exception.

andrei

andrei

A is correct.
Still, it could throw java.nio.file.AccessDeniedException in case if same files are not accessible.