• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NIO2 URI Runtime Exception

 
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
On page 458 of the study guide for OCP8 (Boyarsky, Selikoff) it is stated that the first Path statement below:

Path path1 = Paths.get(new URI("file://pandas/cuddly.png"));

Results in a runtime exception. However when I tried this on my own system (Windows 10), I did not get any runtime exception. Can someone help with this please?

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See the paragraph after this example: "The first example actually throws an exception at runtime, as URIs must reference absolute paths at runtime" and see the feature on the previous page titled "Absolute vs a Relative is file system dependent".

In other words, it is file system dependent to some degree whether the runtime exception will be thrown.
 
John Freeman
Greenhorn
Posts: 21
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Scott Selikoff wrote:See the paragraph after this example: "The first example actually throws an exception at runtime, as URIs must reference absolute paths at runtime" and see the feature on the previous page titled "Absolute vs a Relative is file system dependent".

In other words, it is file system dependent to some degree whether the runtime exception will be thrown.



Thanks for the reply Scott. In the example I posted above, I added a check :

System.out.println(path1.isAbsolute());

and this returned true, so this explained why this resulted in no runtime exception.

Then I tried this:



and this time I got a runtime exception. So it seems like the schema "file://" made the difference in making it an absolute path on my system, therefore I didn't need the 3 slashes as in path3 on page 458.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic