You never increment i in your while loop. Even if you did that you rely on the file containing at least 300 doubles.