import java.io.*; import java.lang.*; import java.util.*; class ReadDB { public static void main(String[] args) { try{ FileReader in = new FileReader(args[0]); BufferedReader data = new BufferedReader(in); // read the first record of input file String CurrentRecord = data.readLine(); String attribute; StringTokenizer extractor; int sum = 0; // Read and process every record while (CurrentRecord!=null) { // use tokenizer to extract each attribute in a record extractor = new StringTokenizer(CurrentRecord, " \t\n"); // extract the first attribute, which is the StudentNumber attribute = extractor.nextToken(); System.out.print("StudentNumber: " + attribute + '\t'); // extract the second attribute, which is the LastName attribute = extractor.nextToken(); System.out.print("LastName: " + attribute + " " + '\t'); // extract the third attribute, which is the grade attribute = extractor.nextToken(); System.out.println("Grade: " + attribute); // sum the grade of all the records sum = sum + (new Integer(attribute)).intValue(); // read the next record CurrentRecord = data.readLine(); } System.out.println("sum of grades: " + sum); in.close(); data.close(); } // input file must have exactly one record with 3 attributes each line catch (NumberFormatException e){ System.out.println("Data format error in input file"); } // I/O errors catch (IOException e){ System.out.println("Unable to read input file"); } } }