(a) Reading the first line and performing initialization; (b) extracting and converting the first two tokens; (c) simple catch to display an error message.
(a) String aLine = superStore.readLine(); if ( aLine == null ) throw new Exception("empty file"); StringTokenizer t = new StringTokenizer(aLine, ","); (b) //get the product and attribute counts productsNum_ = Format.atoi(t.nextToken()); productsAttrNum_ = Format.atoi(t.nextToken()); int i; // read in the names of the attributes productsAttr = new StringBuffer[productsAttrNum_]; for ( i = 0; i < productsAttrNum_ ; i++) { productsAttr[i] = new StringBuffer(""); productsAttr[i].append(t.nextToken()); } // create the products and set up the store. for ( i = 0; i < productsNum_ ; i++ ) { aLine = superStore.readLine(); if ( aLine == null ) throw new Exception("unexpected empty line"); t = new StringTokenizer(aLine, ","); Product aProduct = new Product ( t.nextToken(), Format.atoi(t.nextToken()), Format.atof(t.nextToken())); products_.addElement(aProduct); } } (c) catch (Exception e) { errorDialog (" Problem with reading the data file "); System.exit(1); } }