这是我已经搞砸了一天的功能。出于某种原因,它一遍又一遍地在 csv 中写入最后一个值,而不是通过行进行解析。我输入了一些打印语句,看起来行内容正确写入数组,但被最后一个值覆盖。任何帮助都会很棒,谢谢。
public int csvCombine(ArrayList <Indexstruct> todaysCSV, int totalconvo, String date) throws IOException{
String rows = null;
Indexstruct templist=new Indexstruct();
String [] rowArray= new String [2];
FileReader fr = new FileReader(date + ".csv");
BufferedReader br = new BufferedReader(fr);
rows= br.readLine();
rowArray=rows.split(",");
totalconvo+=Integer.parseInt(rowArray[0]); //Reads in total amount of words spoken and adds it to the CSV value of words spoken
final int csvSize=Integer.parseInt(rowArray[1]); //Read in size of csvList
for(int count=0; count<csvSize-1; count++){
rows = br.readLine();
rowArray = rows.split(","); // Reads lines into an array, takes array values and places them into an object of type indexStruct to write into ArrayList
templist.numOfUses=Integer.parseInt(rowArray[1]); //sets object num of uses
templist.Word=rowArray[0]; //sets object word
todaysCSV.add(count, templist); //adds object to csv ArrayList
}
br.close();
return totalconvo;
}