Here is my code to read a text file line per line.
ArrayList<Student> studentCollection = new ArrayList<Student>();
BufferedReader in = null;
try {
in = new BufferedReader(new FileReader("StudentAnswers2.txt"));
String read = null;
while ((read = in.readLine()) != null)
{
read = in.readLine();
String[] splited = read.split(",");
int[] answersTrans = new int[20];
for(int i = 0; i < 20; i++)
{
answersTrans[i] = Integer.parseInt(splited[i+3]);
}
studentCollection.add(new Student(splited[0], splited[1], splited[2], answersTrans));
}
Context: I am trying to set each comma separated value as fields of a List of Student objects ( one line per Student). The first 3 values need to go in as String parameters, and the following 20 values go in as one int[] array.
Here's the content of the txt file:
C97288501,Byrne,John,0,3,3,0,2,4,0,1,4,5,0,3,3,1,2,4,2,0,4,5 D11255403,Smith,Eileen,1,3,2,0,4,3,1,4,5,0,3,3,1,3,4,5,0,5,4,0 C06623662,Doyle,Mary,1,4,3,3,2,2,1,1,4,5,3,3,3,5,2,4,2,5,4,5 C02887223,Radecki,Jason,2,4,3,0,2,2,4,1,0,2,3,3,5,0,4,4,0,4,0,5 D11123581,Hanley,Nora,1,0,2,2,3,0,0,1,5,4,3,3,0,3,2,4,0,5,4,4