Reputation: 18712
My program generates two files. The first one that gets generated is usually huge, normally around 20GB. The one after that is a 'one line' file. The second file's content (one line) is the header for the first file. So my output should be one file that combines the two. On a memory constraint, I can't create another file to combine the two. What's the best way to go over that?
Upvotes: 0
Views: 132
Reputation: 115348
You cannot just "insert" data in the middle of the file. Using RandomAccessFile will override the data that is already written to specific position of the file.
So, the first solution is (if it is possible) create the header and then append your 20GB. If it is not possible but you can estimate the length (in bytes) of your header you can write garbage if the same length to the beginning of the file, then write your data, then go to the beginning of the file and write (override) the header.
Upvotes: 1