/* Array4.java CIS 160 David Klick 2004-11-01 Reading parallel arrays from a file. */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; public class Array4 { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("people2.txt")); final int MAXSIZE = 100; int numRecs = 0; String[] names = new String[MAXSIZE]; int[] ids = new int[MAXSIZE]; String s; s = in.readLine(); while (s != null) { if (numRecs < MAXSIZE) { names[numRecs] = processName(s); ids[numRecs] = processID(s); numRecs++; } else { System.out.println("Error: Too many records in file"); break; } s = in.readLine(); } in.close(); for (int i=0; i= 0) { if (sb.charAt(ndx) == '"') sb.deleteCharAt(ndx); ndx--; } return sb.toString().trim(); } public static int processID(String s) { StringTokenizer tok = new StringTokenizer(s, ","); if (tok.countTokens() != 2) { System.out.println("Invalid number of fields in record"); return -1; } return Integer.parseInt(tok.nextToken()); } }