aspose file tools*
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 Spring in Action this week in the Spring 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: 18896
    
  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: 19719
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to append to the start of file?