public class driver
{
private static ArrayList<String> arrayList ;
TownBankRecord TBR = new TownBankRecord();
ArrayList<Record> TBList = new ArrayList<Record>();
public void getDate()
{
try
{
BufferedReader br = new BufferedReader (new FileReader ("data/bank-data.csv"));
String line= " ";
int tokenCount=0;
//BankRecord bank= new BankRecord();
while((line=br.readLine())!=null)
{
if (!line.equals(","))
{
StringTokenizer st = new StringTokenizer(line,",");
while (st.hasMoreTokens())
{
arrayList.add(st.nextToken());
tokenCount++;
}
}
if (tokenCount==11)
{
er = new TownBankRecord(arrayList);
TBList.add(er);
tokenCount=0;
}
}
}
catch (FileNotFoundException ex)
{
System.out.println(ex.getMessage());
}
catch (IOException e)
{
System.err.println("Caught IOException: "
+ e.getMessage());
}
}
}
上述代碼從CSV文件中讀取。我使用了一個tokenizer,它從每一行獲取令牌,然後將它們傳遞給一個String的ArrayList。 ArrayList然後被轉移到TownBankRecord的對象er
,然後最終轉移到TBlist(記錄數據類型)。我有以下錯誤呃:初始化ArrayList時出錯
cannot find symbol
symbol: variable er
location: class nidhin.driver.
任何想法?
您打算接受答案嗎?你有三個優秀的,正確的答案。你不必接受我的,即使是因爲它是最高票數。 – CajunLuke 2012-02-25 01:21:16