• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to append to the start of file?

 
Kums Vijayan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to append to the start of file?
 
Henry Wong
author
Marshal
Pie
Posts: 20881
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic