-1
How can I write to a file without deleting what’s inside it? I’m using the classes below.
public void criarArquivos() throws IOException{
/*1 forma*/
FileWriter arqTeste = new FileWriter("teste.txt");
PrintWriter gravaTeste = new PrintWriter(arqTeste);
gravaTeste.println("Jesus is Perfect.");
arqTeste.close();
/*2 forma*/
Formatter arquivo = new Formatter("teste2.txt");
arquivo.format("Jesus is love, but Justice too.");
arquivo.close();
}
public void lerArquivos() throws IOException{
/*1 forma*/
FileReader obter = new FileReader("teste.txt");
BufferedReader receber = new BufferedReader(obter); //pq tem advertencia?
String frase = receber.readLine();
while(frase != null) {
System.out.println(frase);
frase = receber.readLine();
}
/*2 forma*/
FileInputStream arq = new FileInputStream("teste2.txt");
InputStreamReader ler = new InputStreamReader(arq);
BufferedReader leitura = new BufferedReader(ler); //pq tem advertencia?
String linha = leitura.readLine();
while(linha != null) {
System.out.println(linha);
linha = leitura.readLine();
}
}
Your question title differs from the content. You want to add a text to a file that already exists, this?
– Sorack
Yes, having a file that already exists and already has a content, I want to write in it without erasing what has already written
– Carlos Alexandre