开发者

How to load a file into Iphone documents directory?

开发者 https://www.devze.com 2022-12-22 18:55 出处:网络
I have several large files that I want to load into the applications document folder and then call up from there on demand.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消