Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Why is this string tokenizer making me cast to string?
  2. try
  3.             {
  4.                 BufferedReader infileCust =
  5.                         new BufferedReader(new FileReader("C:\custDat.txt"));
  6.     }
  7.       catch(FileNotFoundException fnfe)
  8.             {
  9.                 System.out.println(fnfe.toString());
  10.             }
  11.             catch(IOException ioe)
  12.             {
  13.                 System.out.println(ioe.toString());
  14.             }
  15.         }
  16.  
  17.         public static void createCustomerList(BufferedReader infileCust,
  18.                 CustomerList custList) throws IOException
  19.     {    
  20.         String  FirstName;
  21.         String  LastName;
  22.         int  CustId;
  23.  
  24.  
  25.         //take first line of strings before breaking them up to first last and cust ID
  26.         String StringToBreak = infileCust.readLine();
  27.         //split up the string with string tokenizer
  28.         StringTokenizer st = new StringTokenizer(StringToBreak);
  29.  
  30.         while(st.hasMoreElements()){
  31.         FirstName = (String) st.nextElement();
  32.         LastName = (String) st.nextElement();
  33.         CustId = Integer.parseInt((String) st.nextElement());
  34.  
  35.         }