Java - How do I get last line using Scanner?
- by aloh
while( inStream.hasNextLine() )
{
...
lineList.add( inStream.nextLine() );
}
...
lineList is an ArrayList. The code is reading everything nicely except it won't grab the last line. The last two lines in the text file end like this:
"a sentence here..."
<a blank line here. the blank line is the last line>
I'm assuming it won't grab it since hasNextLine() is not detecting another line after this one?
What's a way to grab the last line? I thought reading until it was EOF and then catching the exception might work but there doesn't seem to be a way to do that.