tags:

views:

61

answers:

1

I want to append the content of fileA to fileB. As fileA is large, I would like to do this in a memory-efficient way, i.e. without reading the entire content of fileA into memory.

+3  A: 
  • Open fileB in append mode.
  • Read a block at a time, of a suitable size, from fileA, and write it to fileB.

This way, you will read the entire contents of fileA into memory, but not all at once. A suitable block size needs to chosen, and I would recommend something pretty big if you have the RAM to spare. A large block size minimizes the number of OS calls. Try 1 MB (if you're in a typical desktop environment, that should be fine).

unwind