Home > Back-end >  How to efficiently removed text file front part?
How to efficiently removed text file front part?

Time:12-20

Program runs, for some leave logging operation, time, the file is too large, want to will be the first to write log (file front part) removed, i.e., the first to write the first to be removed, retain a new record, hope the interception on the original file , ftruncate () function is parts removed after the file, on the contrary,

(will return the record to the newly created file except method),

CodePudding user response:

1. Open the original file, jump to the place you want to keep judge (reading),
2. Get the current file pointer position ftell, access to the file size fseek jump to the end of the file, and hop back into began to save content,
3. All of the content of the remaining read into memory,
4. Close the file
5. Write opens the file (will clean up the file content)
6. To write the contents of the memory into the file,
  • Related