views:

36

answers:

1
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectoryPath = [paths objectAtIndex:0];
    fileName = [documentsDirectoryPath stringByAppendingPathComponent:@"user.txt"];
        NSFileHandle *myHandle = [NSFileHandle fileHandleForUpdatingAtPath:fileName];
    [myHandle seekToEndOfFile];
NSData *dataName = [uname dataUsingEncoding: NSUnicodeStringEncoding];

    if ([dataName writeToFile:fileName atomically:YES])
        NSLog(@"writeok");

        [myHandle seekToEndOfFile];

** I edited the question. Now I am using NSFileHandle. Still the problem persist.

I using the following code to write in a file. The file does not get updated.

Is there any problem with the code?

+2  A: 

You cannot write to files in the Bundle. As the Bundle is code signed, any attempt to change the files in the bundle would break the signing. You need to move the file to the Documents directory and work on it there.

RichB
Rich, Yes I am not writting it in bundle. The problem is that i want append in new line in the file. But it override the file. So, hw to append in the new line of a file?
is NSFileHandle is useful?
(The code above is writing to a file in the Bundle).The writeToFile:atomically:encoding:error: method above overwrites the file if it exists. You could either read the contents of the file first, append to that string what you want and write it back as above or as you say use NSFileHandle.
RichB