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.
EDIT: MORE INFO
public void readLines()
{
lineList = new ArrayList();
try
{
inStream = new Scanner( new File( fileName ) );
}
catch( FileNotFoundException e )
{
System.out.println( "Error opening the file. Try again." );
}
if ( inStream != null )
{
while( inStream.hasNextLine() )
{
++originalLines;
lineList.add( inStream.nextLine() );
}
inStream.close();
}
}
There's the whole method. Anything wrong?
EDIT: EVEN MORE INFO
public static void main(String[] args)
{
Scanner inStream = null;
String test = "";
inStream = new Scanner( test );
while( inStream.hasNextLine() )
{
System.out.println( inStream.nextLine() );
}
}
It will not pick up an empty string but it will pick up a whitespace " "