如何将文件加载到iPhone文档目录中?
我有几个大文件想要加载到应用程序文档文件夹中,然后根据需要从那里调用。
我看到的建议是将它们放在资源文件夹中,然后在应用程序加载时将它们复制到文档文件夹中。我假设如果我这样做,这些大文件将在应用程序启动时全部加载到内存中,然后留在那里...
是否有某种方法可以在安装应用程序时让这些文件直接进入文档文件夹,并且仅在需要时才加载到内存中?
谢谢...
I have several large files that I want to load into the applications document folder and then call up from there on demand.
The suggestion I've seen is to put them in the resources folder and then when the application loads copy them into the documents folder. I assume that if I do this, these large files will all be loaded into memory when the application starts up and then stay there...
Is there some way of having these files go directly into the documents folder when the application is installed, and get loaded into memory only when they are called for?
Thanks...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法在安装时自动执行此操作。
您可以像这样使用
NSFileManager
来复制文件。There's no way to do this automatically at the installation.
You can use
NSFileManager
like that to copy your files.取决于文件最初驻留在哪里。如果在你的包中,那么使用 NSFileManager,就像 gcamp 所说的那样。如果您从网络下载它们,或者即时生成它们,请使用 NSOutputStream - 这是用于将二进制或文本数据从内存写入文件的 API。或者使用 POSIX open()/write(),老派。
Depends on where do the files originally reside. If in your bundle, then use NSFileManager, like gcamp said. If you download them from the 'Net, or generate them on the fly, use NSOutputStream - that's the API for writing binary or text data from memory into files. Or use POSIX open()/write(), old school.