File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Regarding InputStream doubts.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Regarding InputStream doubts.." Watch "Regarding InputStream doubts.." New topic

Regarding InputStream doubts..

Chandra Mohan
Ranch Hand

Joined: Oct 06, 2003
Posts: 62
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.

Thanks and Regards
Chandra Mohan
Rob Spoor

Joined: Oct 27, 2005
Posts: 19845

"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

How To Ask Questions How To Answer Questions
I agree. Here's the link:
subject: Regarding InputStream doubts..