wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "I/O problem" Watch "I/O problem" New topic
Author

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.

Regards,
Sriram.V


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

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


~Suresh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: I/O problem
 
Similar Threads
Wrong output
java program using a class fraction
sorting fractions problem
Passing values between classes in two separate files
null pointer exception