0

如下所示的代码,我正在尝试保存所有字符串。但是,即使它显示 txt created 但没有 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);
    }
4

0 回答 0