如何在附加适用于iOS SDK本地资源txt文件字符串 [英] How to append string in local resource txt file for iOS sdk

查看:208
本文介绍了如何在附加适用于iOS SDK本地资源txt文件字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图追加字符串到本地的资源文件,但我无法找到一个解决方案。我想为所有的函数调用的日志文件在我的应用程序,所以如果它崩溃,我可以看到它的功能就停止了。

I have been trying to append strings to a local resource file but I am having trouble finding a solution. I am trying to create a log file for all the function call in my application so if it crashes I can see which function it stopped on.

我创建了一个log.rtf文件,但我不能在这个文件中写入。是否有人可以帮助,而无需重写整个事情我一个字符串附加到这个文件?

I have created a log.rtf file, but am not able to write in this file. Can someone please help me append a string to this file without having to overwrite the entire thing?

推荐答案

我有以下使用code为上述问题。

I have use following code for the above problem.

NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [documentPaths objectAtIndex:0];
NSString *logPath = [[NSString alloc] initWithFormat:@"%@",[documentsDir stringByAppendingPathComponent:@"log.rtf"]];
NSFileHandle *fileHandler = [NSFileHandle fileHandleForUpdatingAtPath:logPath];
[fileHandler seekToEndOfFile];
[fileHandler writeData:[text dataUsingEncoding:NSUTF8StringEncoding]];
[fileHandler closeFile];

这篇关于如何在附加适用于iOS SDK本地资源txt文件字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆