Java - Añadir lineas a un fichero q ya existe

 
Vista:

Añadir lineas a un fichero q ya existe

Publicado por Toliña (20 intervenciones) el 23/10/2006 18:29:40
Hola! Tengo un problema al intentar añadir una linea a un fichero que ya existe y es que me lo borra todo. Necesito q añada una linea al final. Alguien me puede ayudar? Muchas Gracias!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Añadir lineas a un fichero q ya existe

Publicado por Tom (5 intervenciones) el 23/10/2006 19:14:56
Copio y pego de la documentación del API de Java:

FileOutputStream

public FileOutputStream(File file,
boolean append)
throws FileNotFoundException

Creates a file output stream to write to the file represented by the specified File object. _____If the second argument is true, then bytes will be written to the end of the file rather than the beginning.____ A new FileDescriptor object is created to represent this file connection.

First, if there is a security manager, its checkWrite method is called with the path represented by the file argument as its argument.

If the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason then a FileNotFoundException is thrown.

Parameters:
file - the file to be opened for writing.
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
SecurityException - if a security manager exists and its checkWrite method denies write access to the file.
Since:
1.4
See Also:
File.getPath(), SecurityException, SecurityManager.checkWrite(java.lang.String)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil

RE:Añadir lineas a un fichero q ya existe

Publicado por chuidiang (950 intervenciones) el 24/10/2006 05:03:39
Hola:

Como comenta Tom, el truco es llamar a FileOutputStream poniendole un true en el constructor detrás del nombre de fichero

FileOutputStream fos = new FileOuputStream ("fichero", true);

Se buena.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar