That's not really any different from what the OP is doing, is it? The problem is, as explained by the OP, that the file only contains a single line. Reading that single line is a problem. Reading that single line from the guard of a while statement isn't suddenly going to fix it.