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

查看:20
本文介绍了如何在 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?

推荐答案

我使用以下代码来解决上述问题.

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天全站免登陆