Created
August 9, 2019 01:49
-
-
Save parzibyte/5ce28b856e82e6cb7ce4977d9ebf3fcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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