Usando o tokenizer de string para definir criar matrizes a partir de um arquivo de texto?
Ei. Você pode ter visto recentemente uma postagem minha procurando ajuda, mas eu fiz isso errado antes, então vou começar de novo e começar o básico.
Estou tentando ler um arquivo de texto que se parece com isso:
FTFFFTTFFTFT
3054 FTFFFTTFFTFT
4674 FTFTFFTTTFTF
... etc
O que eu preciso fazer é colocar a primeira linha em uma String como a chave de resposta.
Em seguida, preciso criar uma matriz com a identificação do aluno (os primeiros números). Então, preciso criar uma matriz paralela à identificação do aluno que contenha as respostas do aluno.
Abaixo está o meu código, e eu não consigo descobrir como fazê-lo funcionar assim, e eu queria saber se alguém poderia me ajudar com isso.
public static String[] getData() throws IOException {
int[] studentID = new int[50];
String[] studentAnswers = new String[50];
int total = 0;
String line = reader.readLine();
strTkn = new StringTokenizer(line);
String answerKey = strTkn.nextToken();
while(line != null) {
studentID[total] = Integer.parseInt(strTkn.nextToken());
studentAnswers[total] = strTkn.nextToken();
total++;
}
return studentAnswers;
}
Portanto, no final do dia, a estrutura da matriz deve se parecer com:
studentID [0] = 3054
studentID [1] = 4674
... etc
studentAnswers [0] = FTFFFTTFFTFT
studentAnswers [1] = FTFTFFTTTFTF
Obrigado :)