Create a certain size file and filled with no data on iOS

帅比萌擦擦* 提交于 2019-12-13 19:38:19

问题


I'm developing an iphone app, I need to create a certain size file on filesystem and filled with NO data first, then seek to a offset and write data when get data from somewhere else
How can I do it?


回答1:


The lseek BSD function is explicitly capable of that.

man lseek:

The lseek() function allows the file offset to be set beyond the end of the existing end-of-file of the file. If data is later written at this point, subsequent reads of the data in the gap return bytes of zeros (until data is actually written into the gap).




回答2:


NSMutableData or fseek is probably what you want



来源:https://stackoverflow.com/questions/3967577/create-a-certain-size-file-and-filled-with-no-data-on-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!