permaculture playing cards*
The moose likes Beginning Java and the fly likes How to append to the start of file? 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 to the start of file?" Watch "How to append to the start of file?" New topic
Author

How to append to the start of file?

Kums Vijayan
Greenhorn

Joined: Jan 25, 2010
Posts: 11
How to append to the start of file?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18509
    
  40

Kums Vijayan wrote:How to append to the start of file?


Well, by definition, "append" means to the end, doesn't it? Or do you simply mean write, but don't truncate the file? If you do, take a look at the java.io.RandomAccessFile class.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

If you need to prepend to a file (that's adding to the start) while keeping the rest intact you have to read the file first, then write all over again with the new data first.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to append to the start of file?
 
Similar Threads
Line Feed Carriage Return problem
JFileChooser
How to make each log entry start on a new line?
appending node to xml file
Finding a word in a file