1
I’m trying to add lines to a report, but the new lines are overwriting the old ones.
Class with main method:
import java.io.FileNotFoundException;
public class TesteInscricoes {
public static void main(String[] args) throws FileNotFoundException {
Equipante gabriel = new Equipante();
gabriel.setNome("Gabriel");
Equipante milena = new Equipante();
milena.setNome("Milena");
InscricaoDeEquipante inscricaoDeEquipante = new InscricaoDeEquipante();
inscricaoDeEquipante.inscreveEquipantes(gabriel);
inscricaoDeEquipante.inscreveEquipantes(milena);
}
}
Class making the inscription:
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
public class InscricaoDeEquipante {
public void inscreveEquipantes(Equipante equipante) throws FileNotFoundException {
PrintWriter inscreve = new PrintWriter(new FileOutputStream(new File("Inscricoes.csv")), true);
inscreve.append(equipante.getNome());
inscreve.close();
}
}
At the end, the file presents only the name "Milena".
I’m starting with java and I’m struggling with IO.
What I need to use to get the expected result??
In fact, I see that I missed the constructor where I put the parameter
true
. Regarding the second note, I chose Printwriter because I find it easier, but in this case what is recommended to use??– Gabriel Hardoim