Reject the empty lines at end of text file while reading using Java. -
i need read text file using java. not problem. need reject empty lines @ end of file. file quite large, around 1000000 or lines. need process each line, 1 @ time. if empty.
but, if empty lines @ end of file, need reject it. note there can multiple empty lines @ end of file.
any quick solutions? want write fileutility.trimemptylinesandend(file input). cant help feeling might have written already.
any help appreciated.
note:
i have read link. java: find if lastly line of file empty. not trying do. need reject multiple empty lines.
when find empty line, increment counter number of empty lines. if next line empty, increment counter. if reach end of file, go on on want (ignoring empty lines found). if reach non-empty line, first whatever process empty line, repeating each empty line counted. process non-empty line normal, , go on through file. also, don't forget reset empty line counter zero.
pseudo code:
emptylines = 0; while (the file has next line) { if (line empty) { emptylines++; } else { if (emptylines > 0) { (i = 0; < emptylines; i++) { process empty line; } emptylines = 0; } process line; } }
java
No comments:
Post a Comment