Ask Your Question
4

Why does WriteFile not append, but always overwrite?

asked 2022-11-25 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2021-09-11 17:00:00 +0000

plato gravatar image

The WriteFile function in Windows operating system always overwrites the existing content when writing to a file because it is designed to write at a specific position in the file, which is specified by the file pointer. When a write operation is performed, the file pointer is moved to the next available position in the file, and the data is written at that location, replacing any content that may exist at that position.

If you want to append data to the end of an existing file, you can move the file pointer to the end of the file using the SetFilePointer function and then use the WriteFile function to write the data at the new position. Alternatively, you can use a file operation that is specifically designed for appending data to the end of a file, such as the FILEAPPENDDATA flag in the CreateFile function, or the AppendFile function.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-11-25 11:00:00 +0000

Seen: 14 times

Last updated: Sep 11 '21