write data line by line on iphone

后端 未结 4 1337
抹茶落季
抹茶落季 2020-12-11 08:37

i can write to a text file on iphone..but each time i write my previous value is erased, is there any way to keep writing data separated by \\n??

this is my code

4条回答
  •  萌比男神i
    2020-12-11 09:09

    Use NSFileHandle method seekToEndOfFile and the call to writeData

    NSFileHandle *aFileHandle;
    NSString *aFile;
    
    aFile = [NSString stringWithString:@"Your File Path"]; //setting the file to write to
    
    aFileHandle = [NSFileHandle fileHandleForWritingAtPath:aFile]; //telling aFilehandle what file write to
    [aFileHandle truncateFileAtOffset:[aFileHandle seekToEndOfFile]]; //setting aFileHandle to write at the end of the file
    
    [aFileHandle writeData:[toBeWritten dataUsingEncoding:nil]]; //actually write the data
    

提交回复
热议问题