Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to append in a file from beginning.

 
saurabh agr
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello all,
i am doing some file related work at some point i want to append the file from the beginning but i don't know how to do this, please help.

i m using File Writer constructor with second argument true for appending in the file but it appends from the end of the file but i want to insert something at beginning of the file contents.
Thanks.
 
Rob Spoor
Sheriff
Pie
Posts: 20497
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't, or at least not directly. File systems usually don't allow prepending, only appending. You'll need to use a temporary file as an intermediate solution. Write to the temporary file first, then delete the original file and rename the temporary file to the original file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic