How to trim x bytes from a file

Simple enough, how to remove x number of bytes or a line from the (end) of a file ..? I know how to add bytes - I need to do the opposite.

Unfortunately, I did not find examples of how to do this: - /

NSFileHandle* fh = [NSFileHandle fileHandleForUpdatingAtPath: path]; [fh seekToEndOfFile]; ?? 
+4
source share
2 answers

NSFileHandle has a truncateFileAtOffset method that does exactly what you want.

+6
source

Given that the nSString sFilePath variable is set, you can trim the file to 0 bytes:

 NSFileHandle *hFile; hFile = [NSFileHandle fileHandleForUpdatingAtPath:sFilePath]; [hFile truncateFileAtOffset: 0]; [hFile closeFile]; 
+1
source

All Articles