これを最も基本的な形に分解したと思います。そうでない場合は、お詫びし、編集を試みます。変数を既に文字列に設定している場合、while ループで FirstName の文字列をキャストする必要があるのはなぜですか? 私は何か間違ったことをしていますか?FirstName 変数を、テキスト ファイルなどの最初の単語であるはずの最初のトークンと等しくなるように設定しようとしています。
try
{
BufferedReader infileCust =
new BufferedReader(new FileReader("C:\\custDat.txt"));
}
catch(FileNotFoundException fnfe)
{
System.out.println(fnfe.toString());
}
catch(IOException ioe)
{
System.out.println(ioe.toString());
}
}
public static void createCustomerList(BufferedReader infileCust,
CustomerList custList) 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);
while(st.hasMoreElements()){
FirstName = (String) st.nextElement();
LastName = (String) st.nextElement();
CustId = Integer.parseInt((String) st.nextElement());
}
編集:明らかに、代わりに nextToken() を使用できます。しかし、なぜ私の変数が使用されていないと表示されているのでしょうか? それらは while ループの範囲内にありませんか?