Java OCA OCP Practice Question 3063

Question

Given this code segment:

Path aFilePath = Paths.get("D:\\dir\\file.txt");
Iterator<Path> paths = aFilePath.iterator();
while(paths.hasNext()) {
    System.out.print(paths.next() + " ");
}

Choose the correct option assuming that you are using a Windows machine and the file D:\dir\file.txt does not exist in the underlying file system.

  • a) the program throws a FileNotFoundException
  • b) the program throws an InvalidPathException
  • c) the program throws an UnsupportedOperationException
  • d) the program gets into an infinite loop and keeps printing: path element: dir
  • e) the program prints the following: dir file.txt


e)

Note

the name elements in a path object are identified based on the separators.

to iterate name elements of the Path object does not actually require that the corresponding files/directories must exist, so it will not result in throwing any exceptions.




PreviousNext

Related