• Post Reply Bookmark Topic Watch Topic
  • New Topic

Regarding InputStream doubts..  RSS feed

 
Chandra Mohan
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following line throws null pointer exception while executing in RAD. Not sure about the reason. The XML file has present in the exact path and have access to the system.

InputStream is = Thread.currentThread().getContextClassLoader(). getResourceAsStream("c://services.xml");

Suggestions are welcome.
 
Rob Spoor
Sheriff
Posts: 21052
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"c://services.xml" is not a resource - it's a full path.

Resources are only for files located relative to your class / class loader. If you have the absolute path, use the following:
- new FileInputStream(...) if you need an InputStream
- new File(...).toURI().toURL() if you need a URL
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!