我有一个文本文件,我试图用字符串标记器分解。这是文本文件的几行:
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);
}
}