Hello, i have a problem with this program. I read a file and stored each line in an array of strings. I am trying to write another method but i cant get at the individual strings made by the stringtokenizer. how do i get each of this data out of this thing?
public static void loadDB (String filename) { try { // find length of file to be read BufferedReader in = new BufferedReader (new FileReader (filename)); String line = in.readLine (); size = 0; while (line != null) { line = in.readLine (); size++; } in = new BufferedReader (new FileReader (filename)); // reset bufferedreader in.close ();
//read an array of data //retrieve array size size = Integer.parseInt (in.readLine ());
// set allCities array size CityLocation [] allCities = new CityLocation [size];
// declare variables String prov; String city; int latDeg; int latMin; int longDeg; int longMin;
for (int i = 0 ; i < size ; i++) { allCities = new CityLocation (); String str = in.readLine ();
// extract individual tokens delimited by "," StringTokenizer t = new StringTokenizer (str, ","); prov = t.nextToken (); city = t.nextToken (); latDeg = Integer.parseInt (t.nextToken ()); latMin = Integer.parseInt (t.nextToken ()); longDeg = Integer.parseInt (t.nextToken ()); longMin = Integer.parseInt (t.nextToken ()); } // end for