~/ 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/21636b02-ff2c-4559-abcc-0045025ab2c7/flashcard utf-8 LF