Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

InputStream null problem

807605Jun 22 2007 — edited Jun 23 2007
Hi everybody,
First off, thanks again to everyone who helped me with my hardcoding ArrayList problem. I'm trying to read my file in as a resource, but for some reason it doesn't seem to work. I have my text file side-by-side with the classes in my Java package (called "viewer"), like some of the other posts on this forum said, but my code keeps returning my inputStream as null. My code is:
InputStream is = this.getClass().getClassLoader().getResourceAsStream( "file.txt" );
		BufferedReader reader = new BufferedReader( new InputStreamReader( is ) );
The error keeps getting thrown as a null pointer exception on that second line of code. Can anyone tell me what I'm doing wrong?

Thanks,
Jezzica85
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 21 2007
Added on Jun 22 2007
15 comments
2,731 views