Meaningless Drivel is fun!
The moose likes Beginning Java and the fly likes I/O problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I/O problem" Watch "I/O problem" New topic

I/O problem

andrew cassato
Ranch Hand

Joined: Nov 14, 2010
Posts: 37
I am having trouble reading data from a file called data.txt and storing it as an array of fractions...

i use the debugger and see that it is taking data in and assigning to numerator and denominator but it never gets stored in the array. for some reason it is always showing i = 0 even though i have the i++, so i have no idea why its not incrementing.

Thanks in advance for any help.
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
move int i = 0; outside the while loop
Check with system.out.println it will help you to know the i value inside the while loop.

And one suggestion use finally block to close the scanner.


For java examples,ebooks,interview questions,visit this blog
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

Hint :

[My Blog]
All roads lead to JavaRanch
Suresh Sajja
Ranch Hand

Joined: May 12, 2009
Posts: 34

in While loop, for each iteration, you are re-initializing i to 0

I agree. Here's the link:
subject: I/O problem
It's not a secret anymore!