Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created August 9, 2019 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/5ce28b856e82e6cb7ce4977d9ebf3fcd to your computer and use it in GitHub Desktop.
Save parzibyte/5ce28b856e82e6cb7ce4977d9ebf3fcd to your computer and use it in GitHub Desktop.
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.IOException;
/*
Escribir un archivo de texto con Java
pero no sobrescribir contenido, sino adjuntar
https://parzibyte.me/blog
*/
class Main {
public static void main(String[] args) {
String nombreArchivo = "ejemplo.txt";
try {
// El truco está en pasar true al FileWriter
BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(nombreArchivo, true));
bufferedWriter.write("Adjuntar el contenido, no sobrescribirlo\n");
bufferedWriter.write("parzibyte.me\n");
bufferedWriter.close();
} catch (IOException e) {
System.out.println("Error escribiendo en archivo: " + e.getMessage());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment