For my Ubuntu machine i've got this output:
c:\main\project\Starter.java
And there is no such answer or mentions about OS in the question.
However for this code from the book I've appropriate behavior of getName():
Code: Select all
Path path = Paths.get("/land/hippo/harry.happy");
System.out.println("The Path Name is: "+path);
for(int i=0; i<path.getNameCount(); i++) {
System.out.println("
Element "+i+" is: "+path.getName(i));
}
Element 0 is: land
Element 1 is: hippo
Element 2 is: harry.happy
Looks like my environment can't understand "\\", it works fine with "/" though. I'm using 1.8.0 openjdk-amd64.
Am I missing something or the test contains a mistake?