~/ learn/ comp-308/ cards/ Reading & writing text files
1 of 5

The canonical readLine loop (null = end of file)

The canonical readLine loop (null = end of file)

Answer

String line; while ((line = in.readLine()) != null) { process(line); }

readLine() returns each line without its terminator and null at EOF. The condition assigns then tests against null in one expression.

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/4921f4ce-0cf6-45be-82ed-9433d4ccdf22/flashcard utf-8 LF