This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Reading file into an array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading file into an array" Watch "Reading file into an array" New topic

Reading file into an array

Yafet Negussie

Joined: Mar 17, 2012
Posts: 4
Hi all
I'm trying to read list of numbers from a file to an array. The numbers are read fine, but I'm unable to put them into an array. I cannot see what I'm doing wrong. Can you help please? Here is my code
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
if it's not working because this line prints out 0's
look at the order of your lines of code

starts at
index = 0,
then numbers[0] = ...
then index++
so, in this first time through
is actually

or, it's printing out the value of the next numbers[]

Yafet Negussie

Joined: Mar 17, 2012
Posts: 4
Thank you Michael
that was indeed the problem.
It is sorta covered in the JavaRanch Style Guide.
subject: Reading file into an array
It's not a secret anymore!