Reputation: 87
I want to write a file in the Documents folder of my iPhone app. But when I try to open the path I get the
Cocoa error 257 - Permission Denied.
Here's a little code snippet:
// create path to file
NSURL *path = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] objectAtIndex:0];
NSLog(@"%@", [path description]);
NSError *error = nil;
NSString *filename = [NSString stringWithContentsOfURL:path encoding:NSUTF8StringEncoding error:&error];
NSLog(@"%@", error);
NSLog(@"%@", [filename description]);
Can you tell me please, what's wrong with that code? Thanks!
Upvotes: 3
Views: 1887
Reputation: 52565
It looks as though you're trying to open the documents directory rather than a file in that directory. stringWithContentsOfURL
loads the contents of the file into the NSString
, so it's not a filename.
If filename
should be a path rather than the contents of a file, use stringWithContentsOfURL:
instead.
Upvotes: 1