Writing to a file without overwriting.

Hi all,How can I write to a file without overwriting the exisitng contents?Thank you,Amnesiac.
[122 byte] By [Amnesiaca] at [2007-11-26 19:23:59]
# 1
If you use FileOutputStream use this constructor public FileOutputStream(String name,boolean append)throws FileNotFoundExceptionCreates
p_epia at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you for the reply.I dont want to appen the contents, I want to search for a particular pattern in the file and write the content after the pattern is found without overwriting the contents that exist at that part of the file.Thank you,Amnesiac.
Amnesiaca at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...
# 3

> Thank you for the reply.

>

> I dont want to appen the contents, I want to search

> for a particular pattern in the file and write the

> content after the pattern is found without

> overwriting the contents that exist at that part of

> the file.

>

> Thank you,

> Amnesiac.

That can't be done in a simple way. You need to copy all data after the insert position to a new location in the file.

Kaj

kajbja at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...
# 4
I am thinking of using the RandomAccessFile to get the byte array, use a regular expression and do the inserting and write back the entire contents using the RandomAccessFile.Hope it works, your thoughts?Thank you,Amnesiac.
Amnesiaca at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...
# 5

> I am thinking of using the RandomAccessFile to get

> the byte array, use a regular expression and do the

> inserting and write back the entire contents using

> the RandomAccessFile.

>

> Hope it works, your thoughts?

>

> Thank you,

> Amnesiac.

No need to use RandomAccessFile if you can hold all information in memory. Use FileReader and FileWriter if you are working with text.

Kaj

kajbja at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...
# 6
Thank you for the reply.Yup, got it I actually meant using any streams provided by Java. System.arraycopy amy come to use. Will update you after I do this. I wanted to know if there is shortcut to it that I am not aware of.Thank you,Amnesiac.
Amnesiaca at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...
# 7
> Hope it works, your thoughts?RAF can only overwrite, not really insert. You can replace x bytes with another x bytes, but not much else.
CeciNEstPasUnProgrammeura at 2007-7-9 21:46:11 > top of Java-index,Java Essentials,Java Programming...