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

后端 未结 5 1344
粉色の甜心
粉色の甜心 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:50

    Why not use

    if (line.length()==0) {
        System.out.println("Found an empty line.");
    }
    

    Note: this will detect a blank line anywhere in the file, not just at EOF.

提交回复
热议问题