【问题标题】:updatefile in application folder应用程序文件夹中的更新文件
【发布时间】:2011-06-26 16:58:27
【问题描述】:
NSString *conent = @"One\nnghTwo\nThree\nFour\nFive";
//save content to the documents directory
[conent writeToFile:fileName 
          atomically:NO 
            encoding:NSStringEncodingConversionAllowLossy 
               error:nil];

这是将数据写入文件的代码

我想更新那个文件,我有 2000 行在使用应用程序时要写。

感谢您的帮助。

【问题讨论】:

  • 如何在我在该文件中写入 1000 行后更新该文件在一些我想添加更多数据之后如何添加文本,如果我正在做同样的事情,它将替换数据。

标签: iphone objective-c ipad nsstring


【解决方案1】:

你需要使用 NSFileHandle 类然后 writeData,写入发生在文件指针的当前位置,所以先使用 seekToEndOfFile 移动指针。

NSFileHandle *fh = [NSFileHandle fileHandleForWritingAtPath:@"One\nnghTwo\nThree\nFour\nFive"]
[fh seekToEndOfFile];
[fh writeData:data];

【讨论】:

  • 在你问之前,这里是如何将 NSString 转换为 NSData: NSString * theString=@"abcd"; NSData * data=[theString dataUsingEncoding:NSUTF8StringEncoding];
猜你喜欢
  • 2012-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多