在NSDocumentDirectory中创建子文件夹

Sea*_*ean 5 directory objective-c nsdocument

我只是想知道是否可以在NSDocumentDirectory中创建一个子文件夹并将数据写入该创建的文件夹,如:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);    
NSString *dirPath =[[paths objectAtIndex:0] stringByAppendingPathComponent:@"TestFolder"];  
NSString *filePath =[dirPath stringByAppendingPathComponent:@"testimage.jpg"];  
[imageData writeToFile:filePath atomically:YES];
Run Code Online (Sandbox Code Playgroud)

在此先感谢您的支持!

zou*_*oul 5

writeToFile因为目录不存在可能会失败.如果失败,您可以尝试NSFileManager具有createDirectoryAtPath:attributes:方法的类.