-1

How can I add bytes to an existing file without:

  • overwriting existing bytes
  • reading the file
Community
  • 1
  • 1
  • 1
    Keep the file on the disk in reverse order for use, appending to the end (which is actually the beginning). Use a function to access the file in reverse order when other code needs to access it normally. – umeboshi Dec 26 '14 at 10:45
  • 1
    why the close vote? what part of the problem stztement is unclear? Requestor wants an efficient way to prepend to a disk file – Jasen Dec 27 '14 at 04:08
  • I dont know why the close vote? what part of the problem stztement is unclear? – Muhammad Waqas Khan Abbasi Dec 30 '14 at 06:51

1 Answers1

-1

As you have described it you're going to need operating-system support to do that .
As far as I know this sort of thing is only easy for files stored on punched cards. or if you can add a shim between the userspace and the filesystem.

The best you can hope to do in java is override the file reading an writing code your own application is using to fake the presence of the extra bytes.

I hope you're not trying to corrupt perfectly good text files by adding UTF-8 BOM to the start.

Jasen
  • 11,837
  • 2
  • 30
  • 48