boolean done = false; while (!done) { String input = reader.readLine(); if (input == null) done = true; else do something with the input }