ios – 如何从NSFileHandle *获取文件*?

ios – 如何从NSFileHandle *获取文件*?,第1张

概述旧的解析器依赖于FILE *来工作.但是,适用于iOS的Dropbox Sync API会将NSFileHandle *而不是FILE *作为文件句柄返回. 所以我尝试使用NSFileHandle的fileDescriptor: – (NSFileHandle )readHandle:(DBError *)error Returns a read-only file handle for the 旧的解析器依赖于file *来工作.但是,适用于iOS的DropBox Sync API会将NSfileHandle *而不是file *作为文件句柄返回.

所以我尝试使用NSfileHandle的fileDescriptor:

– (NSfileHandle )readHandle:(DBError *)error

Returns a read-only file handle for the file. If the file is not
cached then the method will block until the file is downloaded.
Returns

A file handle if the file can be read,or nil if an error occurred.

并作为文件传递*:

- (voID)loadDBfile:(DBfile *)dbfile{    DBError *dbError;    NSfileHandle *fileHandle = [dbfile readHandle:&dbError];    if (fileHandle) {         file *file = fileHandle.fileDescriptor;         fseek(file,SEEK_END); // EXE_BAD_ACCESS here!         // ...    }}

但是,fseek行有一个EXE_BAD_ACCESS.

解决方法 fileDescriptor返回底层文件描述符,一个简单的整数,而不是一个file对象(包装文件描述符,但不是同一个东西).使用 fdopen()从文件描述符中获取file对象:

file *file = fdopen([filehandle fileDescriptor],"r"); // Create a read-only file object
总结

以上是内存溢出为你收集整理的ios – 如何从NSFileHandle *获取文件*?全部内容,希望文章能够帮你解决ios – 如何从NSFileHandle *获取文件*?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1065169.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存