• Post Reply Bookmark Topic Watch Topic
  • New Topic

Online mock exams, batch 3, Path question. Wrong answer letter (must be C & E)  RSS feed

 
Tahir Abdullayev
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question:
Assuming the current directory is /home and the directories and files referenced by the program exist, what is true about the following code snippet? (Choose all that apply.)

Path path1 = Paths.get("/lemur/habitat/./party.txt");
Path path2 = path1.subpath(1,4).toAbsolutePath();
System.out.println(Files.lines(path2)
  .flatMap(p -> Stream.of(p.split(",")))
  .filter(s -> s.trim().length()>0)
  .allMatch(s -> s.length()>3));

A. It will access the file /lemur/habitat/party.txt.
B. It will access the file /habitat/party.txt.
C. It will access the file /home/habitat/party.txt.
D. If the String value ,,, is contained within the file, it will definitely print false.
E. If the String value ,hat, is contained within the file, it will definitely print false.
F. It will always print false.
G. The code does not compile

Answer: B, E
-----------
The problem is answer should be C, E. Even description inside answer matches C option. The description says:
"The value path1.subpath(1,4) returns habitat/./party.txt, which we join to the current directory /home with the toAbsolutePath() method in order to see that we are accessing the file /home/habitat/party.txt"

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36659
475
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed. This is already in the errata (search for Lemur) and was originally reported  here
 
Tahir Abdullayev
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My bad. I didn't checked errata for Mock exams. I thought it's only for the book.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36659
475
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tahir Abdullayev wrote:My bad. I didn't checked errata for Mock exams. I thought it's only for the book.

No worries. It's not that easy to parse the errata for the mock exams because there's no question numbers to reference. (The questions are presented in a different order each time.)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!