View Single Post
  #2 (permalink)  
Old 03-19-2008, 07:14 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
Code:
File f1 = new File("students17.dat"); File f2 = new File("passing.dat"); File f3 = new File("honors.dat");
Files with a dat extension are often written and read with highly specialized DataOutput/InputStreams. We generally use a txt extension for reading with a FileReader. It may work; I haven't tried.
The error on line 30 suggests that the reader read something that came up as "null". If the data in the file is only a number on each line then your read method should work.
An impertinent suggestion is to move the sum variable up above the while loop. It gets reset/declared and assigned the value of zero in each trip throught the loop.
Code:
int sum = 0; while((inString = inStream.readLine()) != null) System.out.println(inString); int rec = Integer.parseInt(inString); // int sum = 0; sum += rec;
Reply With Quote