文字列トークナイザーで分割しようとしているテキストファイルがあります。テキストファイルの数行を次に示します。
Mary Smith 1
James Johnson 2
Patricia Williams 3
名、名前、顧客IDに分割しようとしています。
私はこれまでそれを行うことができましたが、それはメアリー・スミスの後で止まります。
これが私のコードです:
public static void createCustomerList(BufferedReader infileCust,
CustomerList customerList) throws IOException
{
String firstName;
String lastName;
int custId;
//take first line of strings before breaking them up to first last and cust ID
String StringToBreak = infileCust.readLine();
//split up the string with string tokenizer
StringTokenizer st = new StringTokenizer(StringToBreak);
firstName = st.nextToken();
while(st.hasMoreElements())
{
lastName = st.nextToken();
custId = Integer.parseInt(st.nextToken());
CustomerElement CustomerObject = new CustomerElement();
CustomerObject.setCustInfo(firstName,lastName,custId);
customerList.addToList(CustomerObject);
}
}