So i am working on something to read the data from the file below and store the data into arrays of objects, so that i can search through those arrays.
YEAR,FIRST,SECOND,THIRD,FOURTH,GRAND-FINAL-PLAYED,WINNING-SCORE,LOSING-SCORE,CROWD
1908,Souths,Easts,Souths,Cumberland,Y,14,12,4000
1909,Souths,Balmain,Souths,Wests,N
1910,Newtown,Souths,Newtown,Wests,Y,4,4,14000
1911,Easts,Glebe,Glebe,Balmain,Y,11,8,20000
1912,Easts,Glebe,Easts,Wests,N
As you can see the grand final is not played every year so some arrays for the score and crowd will be left blank. Im confused like nothing else and just cant seem to do this. This is my code so far below and as you can see its nothing too flash so any help is apprciated.
String file ="data.txt";
//reading
try{
InputStream ips=new FileInputStream(file);
InputStreamReader ipsr=new InputStreamReader(ips);
BufferedReader br=new BufferedReader(ipsr);
String line;
while ((line=br.readLine())!=null){
int commaIdx = 0;
commaIdx = line.indexOf(",", commaIdx);
int arrayIdx = 0;
int beginIdx = 0;
int lineNum = 1;
String[] array1 = null;
array1[lineNum] =" ";
String[] array2 = null;
array2[lineNum] =" ";
String[] array3 = null;
array3[lineNum] =" ";
String[] array4 = null;
array4[lineNum] =" ";
String[] array5 = null;
array5[lineNum] =" ";
String[] array6 = null;
array6[lineNum] =" ";
String[] array7 = null;
array7[lineNum] =" ";
String[] array8 = null;
array8[lineNum] =" ";
String[] array9 = null;
array9[lineNum] =" ";
while (commaIdx > 1)
{
String theValue = line.substring(beginIdx, commaIdx - 1);
switch (arrayIdx)
{
case 1:
array1[lineNum] = theValue;
break;
case 2:
array2[lineNum] = theValue;
break;
case 3:
array3[lineNum] = theValue;
break;
case 4:
array4[lineNum] = theValue;
break;
case 5:
array5[lineNum] = theValue;
break;
case 6:
array6[lineNum] = theValue;
break;
case 7:
array7[lineNum] = theValue;
break;
case 8:
array8[lineNum] = theValue;
break;
case 9:
array9[lineNum] = theValue;
break;
}
arrayIdx++;
beginIdx = commaIdx + 1;
commaIdx = line.indexOf(",", commaIdx+1);
}
lineNum++;
}
br.close();
}
catch (Exception e){
System.out.println(e.toString());
}