开发者

Create Subfolder in NSDocumentDirectory

开发者 https://www.devze.com 2022-12-16 17:48 出处:网络
I just wanted to know if it\'s possible to create a subfolder in the NSDocumentDirectory and write data into that created folder, like:

I just wanted to know if it's possible to create a subfolder in the NSDocumentDirectory and write data into that created folder, like:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
NSString *dirPath =[[paths objectAtIndex:0] stringByAppendingPathComponent:@"TestFolder"];  
NSString *filePath =[dirPath stringByAppend开发者_如何学JAVAingPathComponent:@"testimage.jpg"];  
[imageData writeToFile:filePath atomically:YES];

Thanks in advance for your support!


The writeToFile might fail because the directory does not exist. If it does fail, you could try the NSFileManager class that has a createDirectoryAtPath:attributes: method.


The createDirectoryAtPath:attributes: method has been deprecated.

Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: instead.

0

精彩评论

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

关注公众号