wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes how to append in a file from beginning. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how to append in a file from beginning." Watch "how to append in a file from beginning." New topic
Author

how to append in a file from beginning.

saurabh agr
Ranch Hand

Joined: Apr 14, 2010
Posts: 37
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

Joined: Oct 27, 2005
Posts: 19649
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to append in a file from beginning.
 
Similar Threads
Line Feed Carriage Return problem
Storing data into excisting Data
i will be grateful to u
Storing data into excisting file
How to append the data into exsisting file ?