将字符串附加到txt-iOS

时间:2012-10-02 03:01:23

标签: ios

如下图所示,我试图保存所有字符串。但是,即使它显示了创建的txt但没有创建txt。请参阅此问题Adding string on existing txt file -iOS

 -(void)saveData:(NSString*)data
    {
        NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString *documentDirectory=[paths objectAtIndex:0];
            NSString *fileName=[NSString stringWithFormat:@"%@/%d.txt",documentDirectory,1];
            NSString *content=data;
            NSFileHandle *fileHandler= [NSFileHandle fileHandleForWritingAtPath:fileName];
            [fileHandler seekToEndOfFile];
            [fileHandler writeData:[content dataUsingEncoding:NSUTF8StringEncoding]];
            [fileHandler closeFile];
            NSLog(@"%@",fileName);
    }

0 个答案:

没有答案