How to add a new line to end of a File

Hi,How can I add a new line to end of an existing file without reading and writing the whole file, using java IO classes?
[135 byte] By [MarshallDFXa] at [2007-10-2 0:51:10]
# 1
Did you ever look at the FileWriter and FileOutputStream APIs? Especially at the constructors?
CeciNEstPasUnProgrammeura at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 2
Have a look at RandomAccesFile class documentation, in particular at writeBytes, seek and getFilePointer methods!you should be able to add a line at the end of the file, without reading and writing the whole file!
JoYsTiCka at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 3

> Have a look at RandomAccesFile class documentation,

> in particular at writeBytes, seek and getFilePointer

> methods!

Wow. Just the right methods to append some lines of text to a file.

> you should be able to add a line at the end of the

> file, without reading and writing the whole file!

Who said you have to?

CeciNEstPasUnProgrammeura at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 4
I'm sorry, I wrote my post exactly at the same time you did, I was not meaning tooppose what you said! ;-)
JoYsTiCka at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 5
> I'm sorry, I wrote my post exactly at the same time> you did, I was not meaning tooppose what you said!> ;-)Possibly. But it's still the most uncomfortable way I could think of to do what the OP wants, except maybe using JNI.
CeciNEstPasUnProgrammeura at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 6

Thank you, it worked out really easy with FileWriter

public static void insertLineToFile (String line, String filename)

{

FileWriter fr = null;

try {

fr = new FileWriter(filename, true);

fr.write(line + "\n");

fr.close();

} catch (IOException e) {

e.printStackTrace();

}

}

MarshallDFXa at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 7

Thank you, it worked out really easy with FileWriter

public static void insertLineToFile (String line, String filename)

{

FileWriter fr = null;

try {

fr = new FileWriter(filename, true);

fr.write(line + "\n");

fr.close();

} catch (IOException e) {

e.printStackTrace();

}

}

MarshallDFXa at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...
# 8
>Possibly. But it's still the most uncomfortable way I could think of to do what >the OP wants, except maybe using JNI.You're rigth. > Thank you, it worked out really easy with FileWriterGlad you solved your problem MarshallDFX.
JoYsTiCka at 2007-7-15 18:10:42 > top of Java-index,Java Essentials,New To Java...