Write to Start of file without deleting existing content
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Sridevi_Lakshminarayanan
Posted On:   Friday, February 27, 2004 09:17 AM

Hi,

I have a file that gets dynamically updated from a servlet. I use FileWriter to write to that file. Right now, the data gets appended to the end of the file as i have specified Filewriter(filename, true ). I would like to know if its possible for me to seek to the beginning everytime and write to the top of the file without overriding the existing contents. Please post a sample code if available.


Thanks, Sri.

Re: Write to Start of file without deleting existing content

Posted By:   joe_user  
Posted On:   Sunday, May 23, 2004 10:22 PM

This shouldn't be too hard:



  1. rename old file

  2. write new stuff to new file using old file name

  3. append old file to new file




You could use Java to read and write or simply use an OS command to do the final concatenation.

Re: Write to Start of file without deleting existing content

Posted By:   narender_reddy  
Posted On:   Friday, May 21, 2004 04:47 AM

read the whole into buffer append the new one to that with method append() and store it again.

Re: Write to Start of file without deleting existing content

Posted By:   Steven_Martin  
Posted On:   Friday, February 27, 2004 11:02 AM

did you look at randomaccessfile? People usually require you post YOUR attempts before they post a answer. Helps to weed out the hw seekers.
About | Sitemap | Contact