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]

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.
> 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
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.
> 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
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.