File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes BufferedReader is there method while next exist? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "BufferedReader is there method while next exist?" Watch "BufferedReader is there method while next exist?" New topic
Author

BufferedReader is there method while next exist?

Anissa Pary
Ranch Hand

Joined: Jan 02, 2012
Posts: 40
Hello, Java genius!
Can anyone help please is there a method on a buffereReader while the next on the file exist do when there is no new lines finish. I searched for that but could not find smth. similar do you know how to do that. This is my code I wanted to do like while there is a new line in the file put it in an arrayList when there is no more lines stop.



Equation.txt

2+2
4/3
15*2
14$5

Ok, I added
but now it shows NullPointerException when I debugged it it does two tmes and then throws Exception I think it is because there is no an increasement like int i =0; i++
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

there isn't one in the api, and the 1st five examples i found showed how to do it.

adding example into your search is very helpfull.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4463
    
    8

Just check the return value of the readLine() method. It will return null when it reaches the end of the file.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Anissa Pary wrote:

but now it shows NullPointerException


The only way that code can throw NPE is if br is null or equations is null. And that can only happen if you didn't initialize them, or if you explicitly set them to null. It will not happen from reaching the end of the file. So either you are making one of those things be null, or the NPE is coming from somewhere else.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

if you aren't working in an IDE so can't debug, System.out.println() is your friend print out the variables the line before you use them.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: BufferedReader is there method while next exist?