Read Java file with delimiter

1

I have the following txt file: 38461; Rui Brito; 34561; Rui Brito; 10 31231; Rui Brito; 6

And the following code:

ArrayList<Aluno> listaAlunos = new ArrayList<Aluno>();

public void lerFicheiroPauta(String nomeFicheiro) {
    try {
        Scanner sc = new Scanner(new File(nomeFicheiro));
        sc.useDelimiter("\; || \n");
        while (sc.hasNext()) {
            int número = sc.nextInt();
            String nome = sc.next();
            int nota = sc.nextInt();
            sc.nextLine();

            listaAlunos.add(new Aluno(número, nome, nota));

        }
        sc.close();
    } catch (FileNotFoundException e) {
        System.out.println("Erro na leitura");
        // listaAlunos.clear();
        e.printStackTrace();
    }

}

public String toString() {
    String sc = "";
    for (Aluno a : listaAlunos) {
        sc += a + System.lineSeparator();
    }
    return sc;

}

What happens is that the result is this:

Can anyone help me read the file correctly sff?

    
asked by anonymous 05.06.2016 / 16:16

0 answers