File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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.
I agree. Here's the link:
subject: Reading file into an array
It's not a secret anymore!