I am getting a file error when i am trying to write a string into a file:
NSFileManager *filemgr;
filemgr = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex: 0];
NSString *docFile = [docDir stringByAppendingPathComponent:fileName];
if ([file fileExistsAtPath: docFile] == YES)
{ if(![formatedlogStr writeToFile:LOG_FILE_V1 atomically:YES encoding:NSUTF8StringEncoding error:&error])
{
NSLog(@"Error: %@", [error userInfo]);
}
}
this gives me an error :
Error: {
NSFilePath = "error_log_V1.txt";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=13 \"The operation couldn\U2019t be completed. Permission denied\"";
NSUserStringVariant = Folder;
How to solve the problem I don’t know.
Can anybody help me?
You’re correctly finding a path within your documents directory, but you are trying to log the information to a bare path. You should follow the same procedure to build a path to a file within your sandbox for the log file and use that instead of
LOG_FILE_V1.