iphone - Xcode:iPhone模拟器的目录文件

标签 iphone xcode string directory writetofile

我想在文件“file.txt”中写入一个字符串:我的项目(针对Iphone)中的该文件位于资源内部;我尝试在此文件中写入一个字符串,但它不起作用,我显示了我的代码。

 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *filePath =  [documentsDirectory stringByAppendingPathComponent:@"file.txt"];
NSError *error;
[outputString writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:&error];

我想使用模拟器 xcode 写入此文件,而不是使用设备

最佳答案

我不确定您是否能够在包中编写,但您可以像代码一样在文档目录中编写。你为什么不试试这个呢?

使用相同的代码,您将在以下位置找到您的文件:

/Users/YOURUSER/Library/Application Support/iPhone Simulator/IOSVERSION/Applications/APPID/Documents/file.txt

关于iphone - Xcode:iPhone模拟器的目录文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5593064/

相关文章:

iphone - 是否可以从 UITextField 自定义键盘?

iphone - 我的第一个 iPhone 应用程序测试

iphone - 如何在 iOS 4.2 中将视频放入 iPhone 模拟器相机胶卷中?

iphone - 如何仅使用 UITextField 制作 iOS 计算器

Xcode watch 'invalid expression'

ios - Xcode Bundle 标识符问题

python - 在 Python 中获取最后一个 '/' 或 '\\' 字符

ios - 您的应用程序包签名中的权利与配置文件中包含的权利不匹配

c - 将空字符串分配给获取

string - 使用 Stream API 比较两个字符串并计算差异