Click to See Complete Forum and Search --> : file update w/o rewriting the big whole file


H.J Park
October 14th, 1999, 06:17 AM
Dear Sirs,

I am updating just small part of a big file(40M bytes).
The modified portion is the first 1M Byte, and the rest is same as before.
If I write the whole file again, it will take long long time.

I want to write 1M data and attach the 39M without rewriting it.
How can I program it with VC++?

Please Help Me..

email - hjpark@marsystem.com

Sam Hobbs
October 15th, 1999, 02:12 AM
I hope that you are able to update only the first megabyte as you say. If the position of the other data within the whole file needs to shift by any amount, then you will need to read and write all the data.

The following code will read an entire file (up to INT_MAX in size, which is probably too big to fit) into a CString. You will need to modify this but it should be easy to modify. It should also be easy to determine corresponding code to write it back out.


CFileException FileExc;
CString FileData;
CFile Inputfile;
DWORD n;
if (Inputfile.Open("C:\\CONFIG.SYS", CFile::modeRead, &FileExc)) {
n = __min(Inputfile.GetLength(), INT_MAX);
n = Inputfile.Read(FileData.GetBuffer(n), n);
FileData.ReleaseBuffer(n);
Inputfile.Close();
}