John,

How about checking to see if the file is first valid by reading the first line before the loop starts? If it returns an expected response then continue. If it returns null, then don't bother with the loop.

../mk