テキストファイルがあります。文字列トークナイザで分割しようとしています。ここでは、テキストファイルの数行です:最初の行の後に文字列トークナイザが停止する
Mary Smith 1
James Johnson 2
Patricia Williams 3
私は名、姓と顧客IDに解散しようとしています。
私はこれまでこれを行うことができましたが、マリー・スミスの後で停止します。あなたはあなたのすべてがオフにトークンを投げるために起こっているように、ループの外でのfirstNameを持って、具体的方法を、
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);
}
}
すべての変数宣言にcamelCaseを使用する必要があります。あなたのコード 'StringToBreak'と' CustomerObject'には大文字の頭文字があり、型(クラスとインターフェース)のために予約されています。それは動作しますが、それは混乱につながります。 – helios