aspose file tools*
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 Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Reading file into an array" Watch "Reading file into an array" New topic
Author

Reading file into an array

Yafet Negussie
Greenhorn

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
System.out.println(numbers[index]);
look at the order of your lines of code

starts at
index = 0,
then numbers[0] = ...
then index++
so, in this first time through
System.out.println(numbers[index]);
is actually
System.out.println(numbers[1]);

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

Yafet Negussie
Greenhorn

Joined: Mar 17, 2012
Posts: 4
Thank you Michael
that was indeed the problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Reading file into an array