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 folde开发者_StackOverflow中文版r. 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...
There's no way to do this automatically at the installation.
You can use NSFileManager
like that to copy your files.
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *finalPath = [documentsDirectory stringByAppendingPathComponent:@"documentName"];
[[NSFileManager defaultManager] copyItemAtPath:yourDocumentPath toPath:finalPath error:nil];
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.
精彩评论