java - LineIterator.hasNext() throws exception if last line of the file is not empty -
i have piece of code looks (in java) uses org.apache.commons.io.ioutils.lineiterator;
lineiterator iterator = lineiterator(somefile, defaultcharset()); .... while(iterator.hasnext){ process(iterator); } private string process(lineiterator iterator, somecomplexclass someclass){ while(iterator.hasnext()){ //do using iterator.nextline() } }
this works if input file has empty last row.
input file: line1 line2 (nothing here. empty line)
but if have input file without empty line, lineiterator.hasnext() throws exception saying "java.lang.illegalstateexception: stream closed"
input file: line1 line2 //there no empty line after
is known behaviour of lineiterator? please me try understand why happening this.
update: don't see close() or lineiterator.closequietly(iterator) in code. can cause issue?
open file reading in text editor can show line numbers notepad++ if last line empty.delete last line.
blank space not mean there no line
Comments
Post a Comment