Reading a File, using Scanner, then assigning all values in the file to an array

Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Reading a File, using Scanner, then assigning all values in the file to an array

Hi all,

Let me start off by saying this is my first post, and it comes in a time of dire need (not really), as this code is driving me to madness, slowly but surely.

I'm taking a computer science course in school, and there is an assignment due. Normally, I have no problems with these assignments, seeing as little restrictions are put on them. However, this one is different, in the fact that I MUST take a file containing 1)on the first line, the number of number(years) in the file, and 2)followed by a list of birth years. Following that, I must gather all the years and arrange them based on whichever Chinese zodiac sign they are (chicken, rooster, ox, etc). I am not looking for answers, nor a free ride, but rather help.

I think that it is entering an infinite loop, how I do not know. I originally encountered issues when trying to initialize yearsInFile to the correct size, seeing as I cannot initialize to null, without a null pointer exception. We are not allowed to use ArrayList (because they havent taught us yet, even though I've used it before, evidence of the restrictions I was talking about before).

Not sure if you need it, but here is the rest of my code, just to be safe