Reading no of valid lines in a java program