How to append string in local resource txt file for iOS sdk(如何在 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 文件中附加字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 iOS sdk 的本地资源 txt 文件中附加字符串
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
