BufferedReader readLine() issue: detecting end of file and empty return lines

后端 未结 5 1400
粉色の甜心
粉色の甜心 2021-01-18 09:14

I want my program to do something when it finds the end of a file (EOF) at the end of the last line of text, and something else when the EOF is at the empty line AFTER that

5条回答
  •  醉酒成梦
    2021-01-18 09:40

    You can use BufferedReader.read(char[] cbuf, int off, int len) method. When end of file is reached, return value -1, you can check if the last buffer read ended with a line separator.

    Admittedly, the code would be more complicated as it will have to manage the construction of lines from the read char[] buffers.

提交回复
热议问题